@tarojs/taro-h5 3.5.11 → 3.6.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -544,7 +544,7 @@ declare function onSocketOpen(): void;
544
544
  declare function onSocketMessage(): void;
545
545
  declare function onSocketError(): void;
546
546
  declare function onSocketClose(): void;
547
- declare function connectSocket(options: any): Promise<unknown>;
547
+ declare function connectSocket(options?: Taro.connectSocket.Option): Promise<unknown>;
548
548
  declare function closeSocket(): void;
549
549
  // 帐号信息
550
550
  declare const getAccountInfoSync: (option?: {}, ...args: any[]) => Promise<Partial<TaroGeneral.CallbackResult> & Record<string, unknown> & TaroGeneral.CallbackResult>;
@@ -679,7 +679,7 @@ declare const disableAlertBeforeUnload: (option?: {}, ...args: any[]) => Promise
679
679
  declare const getMenuButtonBoundingClientRect: (option?: {}, ...args: any[]) => Promise<Partial<TaroGeneral.CallbackResult> & Record<string, unknown> & TaroGeneral.CallbackResult>;
680
680
  // 导航栏
681
681
  declare const showNavigationBarLoading: (option?: {}, ...args: any[]) => Promise<Partial<TaroGeneral.CallbackResult> & Record<string, unknown> & TaroGeneral.CallbackResult>;
682
- declare function setNavigationBarTitle(options: any): Promise<Partial<TaroGeneral.CallbackResult> & Record<string, unknown> & TaroGeneral.CallbackResult>;
682
+ declare function setNavigationBarTitle(options?: Taro.setNavigationBarTitle.Option): Promise<Partial<TaroGeneral.CallbackResult> & Record<string, unknown> & TaroGeneral.CallbackResult>;
683
683
  /**
684
684
  * 设置页面导航条颜色
685
685
  */
@@ -1,18 +1,23 @@
1
1
  declare type TCallback<T = Partial<TaroGeneral.CallbackResult>> = (res: T) => Promise<void> | void;
2
2
  interface IMethodParam<T = Partial<TaroGeneral.CallbackResult>> {
3
3
  name: string;
4
- success?: TCallback<T>;
4
+ success?: TCallback<T & TaroGeneral.CallbackResult>;
5
5
  fail?: TCallback;
6
6
  complete?: TCallback;
7
7
  }
8
+ interface IMockPromise {
9
+ resolve?: typeof Promise.resolve | TFunc;
10
+ reject?: typeof Promise.reject | TFunc;
11
+ }
8
12
  export declare class MethodHandler<T = Partial<TaroGeneral.CallbackResult>> {
9
13
  methodName: string;
10
14
  protected __success?: TCallback<T>;
11
15
  protected __fail?: TCallback;
12
16
  protected __complete?: TCallback;
17
+ protected isHandlerError: boolean;
13
18
  constructor({ name, success, fail, complete }: IMethodParam<T>);
14
- success<U = Record<string, unknown>>(res?: Partial<T> & Partial<TaroGeneral.CallbackResult>, resolve?: any): Promise<T & U & TaroGeneral.CallbackResult>;
15
- fail<U = Record<string, unknown>>(res?: Partial<T> & Partial<TaroGeneral.CallbackResult>, reject?: any): Promise<T & U & TaroGeneral.CallbackResult>;
19
+ success<U = Record<string, unknown>>(res?: Partial<T> & Partial<TaroGeneral.CallbackResult>, promise?: IMockPromise): Promise<T & U & TaroGeneral.CallbackResult>;
20
+ fail<U = Record<string, unknown>>(res?: Partial<T> & Partial<TaroGeneral.CallbackResult>, promise?: IMockPromise): Promise<T & U & TaroGeneral.CallbackResult>;
16
21
  }
17
22
  declare type TCallbackManagerParam = (...arr: unknown[]) => void;
18
23
  interface ICallbackManagerOption {
@@ -1,29 +1,38 @@
1
+ import { isFunction } from '@tarojs/shared';
1
2
  export class MethodHandler {
2
3
  constructor({ name, success, fail, complete }) {
4
+ this.isHandlerError = false;
3
5
  this.methodName = name;
4
6
  this.__success = success;
5
7
  this.__fail = fail;
6
8
  this.__complete = complete;
9
+ this.isHandlerError = isFunction(this.__complete) || isFunction(this.__fail);
7
10
  }
8
- success(res = {}, resolve = Promise.resolve.bind(Promise)) {
11
+ success(res = {}, promise = {}) {
9
12
  if (!res.errMsg) {
10
13
  res.errMsg = `${this.methodName}:ok`;
11
14
  }
12
- typeof this.__success === 'function' && this.__success(res);
13
- typeof this.__complete === 'function' && this.__complete(res);
15
+ isFunction(this.__success) && this.__success(res);
16
+ isFunction(this.__complete) && this.__complete(res);
17
+ const { resolve = Promise.resolve.bind(Promise) } = promise;
14
18
  return resolve(res);
15
19
  }
16
- fail(res = {}, reject = Promise.reject.bind(Promise)) {
20
+ fail(res = {}, promise = {}) {
17
21
  if (!res.errMsg) {
18
22
  res.errMsg = `${this.methodName}:fail`;
19
23
  }
20
24
  else {
21
25
  res.errMsg = `${this.methodName}:fail ${res.errMsg}`;
22
26
  }
23
- console.error(res.errMsg);
24
- typeof this.__fail === 'function' && this.__fail(res);
25
- typeof this.__complete === 'function' && this.__complete(res);
26
- return reject(res);
27
+ if (process.env.NODE_ENV !== 'production') {
28
+ console.error(res.errMsg);
29
+ }
30
+ isFunction(this.__fail) && this.__fail(res);
31
+ isFunction(this.__complete) && this.__complete(res);
32
+ const { resolve = Promise.resolve.bind(Promise), reject = Promise.reject.bind(Promise) } = promise;
33
+ return this.isHandlerError
34
+ ? resolve(res)
35
+ : reject(res);
27
36
  }
28
37
  }
29
38
  export class CallbackManager {
@@ -67,12 +76,12 @@ export class CallbackManager {
67
76
  */
68
77
  this.trigger = (...args) => {
69
78
  this.callbacks.forEach(opt => {
70
- if (typeof opt === 'function') {
79
+ if (isFunction(opt)) {
71
80
  opt(...args);
72
81
  }
73
82
  else {
74
83
  const { callback, ctx } = opt;
75
- typeof callback === 'function' && callback.call(ctx, ...args);
84
+ isFunction(callback) && callback.call(ctx, ...args);
76
85
  }
77
86
  });
78
87
  };
@@ -1,5 +1,4 @@
1
1
  import { TaroElement } from '@tarojs/runtime';
2
- export declare const isProd: boolean;
3
2
  export declare function shouldBeObject(target: unknown): {
4
3
  flag: boolean;
5
4
  msg?: undefined;
@@ -2,8 +2,8 @@
2
2
  import Taro from '@tarojs/api';
3
3
  import { addLeadingSlash, getHomePage, stripBasename } from '@tarojs/router/dist/utils';
4
4
  import { Current, hooks } from '@tarojs/runtime';
5
+ import { isFunction } from '@tarojs/shared';
5
6
  import { MethodHandler } from './handler';
6
- export const isProd = process.env.NODE_ENV === 'production';
7
7
  export function shouldBeObject(target) {
8
8
  if (target && typeof target === 'object')
9
9
  return { flag: true };
@@ -85,7 +85,7 @@ export function temporarilyNotSupport(name = '') {
85
85
  type: 'method',
86
86
  category: 'temporarily',
87
87
  });
88
- if (isProd) {
88
+ if (process.env.NODE_ENV === 'production') {
89
89
  console.warn(errMsg);
90
90
  return handle.success({ errMsg });
91
91
  }
@@ -105,7 +105,7 @@ export function weixinCorpSupport(name) {
105
105
  type: 'method',
106
106
  category: 'weixin_corp',
107
107
  });
108
- if (isProd) {
108
+ if (process.env.NODE_ENV === 'production') {
109
109
  console.warn(errMsg);
110
110
  return handle.success({ errMsg });
111
111
  }
@@ -125,7 +125,7 @@ export function permanentlyNotSupport(name = '') {
125
125
  type: 'method',
126
126
  category: 'permanently',
127
127
  });
128
- if (isProd) {
128
+ if (process.env.NODE_ENV === 'production') {
129
129
  console.warn(errMsg);
130
130
  return handle.success({ errMsg });
131
131
  }
@@ -141,7 +141,7 @@ export function processOpenApi({ name, defaultOptions, standardMethod, formatOpt
141
141
  // @ts-ignore
142
142
  const targetApi = (_a = window === null || window === void 0 ? void 0 : window.wx) === null || _a === void 0 ? void 0 : _a[name];
143
143
  const opts = formatOptions(Object.assign({}, defaultOptions, options));
144
- if (typeof targetApi === 'function') {
144
+ if (isFunction(targetApi)) {
145
145
  return new Promise((resolve, reject) => {
146
146
  ['fail', 'success', 'complete'].forEach(k => {
147
147
  opts[k] = preRef => {
@@ -158,7 +158,7 @@ export function processOpenApi({ name, defaultOptions, standardMethod, formatOpt
158
158
  });
159
159
  });
160
160
  }
161
- else if (typeof standardMethod === 'function') {
161
+ else if (isFunction(standardMethod)) {
162
162
  return standardMethod(opts);
163
163
  }
164
164
  else {
@@ -1,2 +1 @@
1
- export declare function isFunction(obj: any): boolean;
2
- export declare const isValidColor: (color: any) => boolean;
1
+ export declare const isValidColor: (color: string) => boolean;
@@ -1,6 +1,3 @@
1
- export function isFunction(obj) {
2
- return typeof obj === 'function';
3
- }
4
1
  const VALID_COLOR_REG = /^#[0-9a-fA-F]{6}$/;
5
2
  export const isValidColor = (color) => {
6
3
  return VALID_COLOR_REG.test(color);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarojs/taro-h5",
3
- "version": "3.5.11",
3
+ "version": "3.6.0-alpha.1",
4
4
  "description": "Taro h5 framework",
5
5
  "browser": "dist/index.esm.js",
6
6
  "main:h5": "dist/index.js",
@@ -31,11 +31,16 @@
31
31
  "jsonp-retry": "^1.0.3",
32
32
  "query-string": "^7.1.1",
33
33
  "whatwg-fetch": "^3.4.0",
34
- "@tarojs/api": "3.5.11",
35
- "@tarojs/router": "3.5.11",
36
- "@tarojs/runtime": "3.5.11"
34
+ "@tarojs/api": "3.6.0-alpha.1",
35
+ "@tarojs/router": "3.6.0-alpha.1",
36
+ "@tarojs/runtime": "3.6.0-alpha.1",
37
+ "@tarojs/shared": "3.6.0-alpha.1"
37
38
  },
38
39
  "devDependencies": {
40
+ "jest": "^29.3.1",
41
+ "jest-fetch-mock": "^3.0.3",
42
+ "jest-localstorage-mock": "^2.4.0",
43
+ "jest-mock-console": "^1.0.0",
39
44
  "react": "^18.2.0",
40
45
  "react-test-renderer": "^18.2.0"
41
46
  },
@@ -0,0 +1 @@
1
+ declare type TFunc = (...args: any[]) => any