From de2c9ce1bc25c58e3892bd899ada6a0a515eae83 Mon Sep 17 00:00:00 2001 From: chenjingyuan Date: Tue, 6 Feb 2018 16:47:20 +0800 Subject: [PATCH 1/2] 1. change es6-promisify to bluebird 2. add index.d.ts --- index.d.ts | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ index.js | 6 +++--- package.json | 2 +- 3 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..630a46d --- /dev/null +++ b/index.d.ts @@ -0,0 +1,60 @@ +export interface ITextShareData { + type: 'text'; + text: string; +} + +export interface IImageShareData { + type: 'image'; + imageUrl: string; + title: string; + description: string; +} + +export interface IWebShareData { + type: 'news'; + imageUrl: string; + webpageUrl: string; + title: string; + description: string; +} + +export interface IPayData { + partnerId: string; + prepayId: string; + nonceStr: string; + timeStamp: string; + package: string; + sign: string; +} + +export function isWXAppInstalled(): Promise; + +export function isWXAppSupportApi(): Promise; + +export function login(data: { + scope: string; +}): Promise<{ + code: string; + appid: string; + lang: string; + country: string; + errCode?: number; + errMsg?: string; +}>; + +export function shareToTimeline( + data: ITextShareData | IImageShareData | IWebShareData, +): Promise; + +export function shareToSession( + data: ITextShareData | IImageShareData | IWebShareData, +): Promise; + +export function pay( + data: IPayData, +): Promise<{ + errCode: string; + errMsg: string; + appid: string; + returnKey: string; +}>; diff --git a/index.js b/index.js index ac27380..1a78c37 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ import { NativeAppEventEmitter, NativeModules } from 'react-native'; -import promisify from 'es6-promisify'; +import Promise from 'bluebird'; const WeChatAPI = NativeModules.WeChatAPI; @@ -57,7 +57,7 @@ function wrapCheckApi(nativeFunc) { return undefined; } - const promisified = promisify(nativeFunc, translateError); + const promisified = Promise.promisify(nativeFunc, translateError); return (...args) => { return promisified(...args); }; @@ -71,7 +71,7 @@ function wrapApi(nativeFunc) { return undefined; } - const promisified = promisify(nativeFunc, translateError); + const promisified = Promise.promisify(nativeFunc, translateError); return async function (...args) { if (!WeChatAPI.isAppRegistered) { throw new Error('注册应用失败'); diff --git a/package.json b/package.json index c22a7d2..b8f1e4b 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ }, "homepage": "https://github.com/reactnativecn/react-native-wx#readme", "dependencies": { - "es6-promisify": "^3.0.0" + "bluebird": "^3.5.1" }, "peerDependencies": { "react-native": "^0.33.0" From 181f03ff3742f39c859ae8e3d5a6e43a9e61aaed Mon Sep 17 00:00:00 2001 From: chenjingyuan Date: Fri, 23 Mar 2018 20:47:30 +0800 Subject: [PATCH 2/2] update index.d.ts --- index.d.ts | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/index.d.ts b/index.d.ts index 630a46d..1a5b840 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,24 +1,24 @@ export interface ITextShareData { - type: 'text'; + type: "text"; text: string; } export interface IImageShareData { - type: 'image'; + type: "image"; imageUrl: string; title: string; description: string; } export interface IWebShareData { - type: 'news'; + type: "news"; imageUrl: string; webpageUrl: string; title: string; description: string; } -export interface IPayData { +export interface IPayReq { partnerId: string; prepayId: string; nonceStr: string; @@ -27,34 +27,34 @@ export interface IPayData { sign: string; } -export function isWXAppInstalled(): Promise; - -export function isWXAppSupportApi(): Promise; +export interface IPayResp { + errCode: number; + errMsg: string; + appid: string; + returnKey: string; +} -export function login(data: { - scope: string; -}): Promise<{ +export interface ILoginResp { code: string; appid: string; lang: string; country: string; errCode?: number; errMsg?: string; -}>; +} + +export function isWXAppInstalled(): Promise; + +export function isWXAppSupportApi(): Promise; + +export function login(data: { scope: string }): Promise; export function shareToTimeline( - data: ITextShareData | IImageShareData | IWebShareData, + data: ITextShareData | IImageShareData | IWebShareData ): Promise; export function shareToSession( - data: ITextShareData | IImageShareData | IWebShareData, + data: ITextShareData | IImageShareData | IWebShareData ): Promise; -export function pay( - data: IPayData, -): Promise<{ - errCode: string; - errMsg: string; - appid: string; - returnKey: string; -}>; +export function pay(data: IPayReq): Promise;