@tarojs/with-weapp 4.0.1 → 4.0.2

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.
@@ -1,127 +1,114 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@babel/runtime/helpers/defineProperty'), require('@babel/runtime/helpers/toConsumableArray'), require('@babel/runtime/helpers/slicedToArray'), require('@babel/runtime/helpers/classCallCheck'), require('@babel/runtime/helpers/createClass'), require('@babel/runtime/helpers/assertThisInitialized'), require('@babel/runtime/helpers/get'), require('@babel/runtime/helpers/inherits'), require('@babel/runtime/helpers/possibleConstructorReturn'), require('@babel/runtime/helpers/getPrototypeOf'), require('@babel/runtime/helpers/typeof'), require('@tarojs/runtime'), require('@tarojs/taro')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@babel/runtime/helpers/defineProperty', '@babel/runtime/helpers/toConsumableArray', '@babel/runtime/helpers/slicedToArray', '@babel/runtime/helpers/classCallCheck', '@babel/runtime/helpers/createClass', '@babel/runtime/helpers/assertThisInitialized', '@babel/runtime/helpers/get', '@babel/runtime/helpers/inherits', '@babel/runtime/helpers/possibleConstructorReturn', '@babel/runtime/helpers/getPrototypeOf', '@babel/runtime/helpers/typeof', '@tarojs/runtime', '@tarojs/taro'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TaroWithWeapp = {}, global._defineProperty, global._toConsumableArray, global._slicedToArray, global._classCallCheck, global._createClass, global._assertThisInitialized, global._get, global._inherits, global._possibleConstructorReturn, global._getPrototypeOf, global._typeof, global.runtime, global.taro));
5
- })(this, (function (exports, _defineProperty, _toConsumableArray, _slicedToArray, _classCallCheck, _createClass, _assertThisInitialized, _get, _inherits, _possibleConstructorReturn, _getPrototypeOf, _typeof, runtime, taro) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tarojs/runtime'), require('@tarojs/taro')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@tarojs/runtime', '@tarojs/taro'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TaroWithWeapp = {}, global.runtime, global.taro));
5
+ })(this, (function (exports, runtime, taro) { 'use strict';
6
6
 
7
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
7
+ const json = JSON;
8
8
 
9
- var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
10
- var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
11
- var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
12
- var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
13
- var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
14
- var _assertThisInitialized__default = /*#__PURE__*/_interopDefaultLegacy(_assertThisInitialized);
15
- var _get__default = /*#__PURE__*/_interopDefaultLegacy(_get);
16
- var _inherits__default = /*#__PURE__*/_interopDefaultLegacy(_inherits);
17
- var _possibleConstructorReturn__default = /*#__PURE__*/_interopDefaultLegacy(_possibleConstructorReturn);
18
- var _getPrototypeOf__default = /*#__PURE__*/_interopDefaultLegacy(_getPrototypeOf);
19
- var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
9
+ const clone = (obj) => json.parse(stringify(obj));
20
10
 
21
- var json = JSON;
22
- var clone = function clone(obj) {
23
- return json.parse(stringify(obj));
11
+ const isArray = Array.isArray || function (x) {
12
+ return {}.toString.call(x) === '[object Array]'
24
13
  };
25
- var isArray = Array.isArray || function (x) {
26
- return {}.toString.call(x) === '[object Array]';
27
- };
28
- var objectKeys = Object.keys || function (obj) {
29
- var has = Object.prototype.hasOwnProperty || function () {
30
- return true;
31
- };
32
- var keys = [];
33
- for (var key in obj) {
14
+
15
+ const objectKeys = Object.keys || function (obj) {
16
+ const has = Object.prototype.hasOwnProperty || function () { return true };
17
+ const keys = [];
18
+ for (const key in obj) {
34
19
  if (has.call(obj, key)) keys.push(key);
35
20
  }
36
- return keys;
21
+ return keys
37
22
  };
38
- function stringify(obj, opts) {
23
+
24
+ function stringify (obj, opts) {
39
25
  if (!opts) opts = {};
40
- if (typeof opts === 'function') opts = {
41
- cmp: opts
42
- };
43
- var space = opts.space || '';
26
+ if (typeof opts === 'function') opts = { cmp: opts };
27
+ let space = opts.space || '';
44
28
  if (typeof space === 'number') space = Array(space + 1).join(' ');
45
- var cycles = typeof opts.cycles === 'boolean' ? opts.cycles : false;
46
- var replacer = opts.replacer || function (key, value) {
47
- return value;
48
- };
49
- var cmp = opts.cmp && function (f) {
29
+ const cycles = (typeof opts.cycles === 'boolean') ? opts.cycles : false;
30
+ const replacer = opts.replacer || function (key, value) { return value };
31
+
32
+ const cmp = opts.cmp && (function (f) {
50
33
  return function (node) {
51
34
  return function (a, b) {
52
- var aobj = {
53
- key: a,
54
- value: node[a]
55
- };
56
- var bobj = {
57
- key: b,
58
- value: node[b]
59
- };
60
- return f(aobj, bobj);
61
- };
62
- };
63
- }(opts.cmp);
64
- var seen = [];
65
- return function stringify(parent, key, node, level) {
66
- var indent = space ? '\n' + new Array(level + 1).join(space) : '';
67
- var colonSeparator = space ? ': ' : ':';
35
+ const aobj = { key: a, value: node[a] };
36
+ const bobj = { key: b, value: node[b] };
37
+ return f(aobj, bobj)
38
+ }
39
+ }
40
+ })(opts.cmp);
41
+
42
+ const seen = [];
43
+ return (function stringify (parent, key, node, level) {
44
+ const indent = space ? ('\n' + new Array(level + 1).join(space)) : '';
45
+ const colonSeparator = space ? ': ' : ':';
46
+
68
47
  if (node && node.toJSON && typeof node.toJSON === 'function') {
69
48
  node = node.toJSON();
70
49
  }
50
+
71
51
  node = replacer.call(parent, key, node);
52
+
72
53
  if (node === undefined) {
73
- return;
54
+ return
74
55
  }
75
- if (_typeof__default["default"](node) !== 'object' || node === null) {
76
- return json.stringify(node);
56
+ if (typeof node !== 'object' || node === null) {
57
+ return json.stringify(node)
77
58
  }
78
59
  if (isArray(node)) {
79
- var out = [];
80
- for (var i = 0; i < node.length; i++) {
81
- var item = stringify(node, i, node[i], level + 1) || json.stringify(null);
60
+ const out = [];
61
+ for (let i = 0; i < node.length; i++) {
62
+ const item = stringify(node, i, node[i], level + 1) || json.stringify(null);
82
63
  out.push(indent + space + item);
83
64
  }
84
- return '[' + out.join(',') + indent + ']';
65
+ return '[' + out.join(',') + indent + ']'
85
66
  } else {
86
67
  if (seen.indexOf(node) !== -1) {
87
- if (cycles) return json.stringify('__cycle__');
88
- throw new TypeError('Converting circular structure to JSON');
68
+ if (cycles) return json.stringify('__cycle__')
69
+ throw new TypeError('Converting circular structure to JSON')
89
70
  } else seen.push(node);
90
- var keys = objectKeys(node).sort(cmp && cmp(node));
91
- var _out = [];
92
- for (var _i = 0; _i < keys.length; _i++) {
93
- var _key = keys[_i];
94
- var value = stringify(node, _key, node[_key], level + 1);
95
- if (!value) continue;
96
- var keyValue = json.stringify(_key) + colonSeparator + value;
97
- _out.push(indent + space + keyValue);
71
+
72
+ const keys = objectKeys(node).sort(cmp && cmp(node));
73
+ const out = [];
74
+ for (let i = 0; i < keys.length; i++) {
75
+ const key = keys[i];
76
+ const value = stringify(node, key, node[key], level + 1);
77
+
78
+ if (!value) continue
79
+
80
+ const keyValue = json.stringify(key) +
81
+ colonSeparator +
82
+ value;
83
+
84
+ out.push(indent + space + keyValue);
98
85
  }
99
86
  seen.splice(seen.indexOf(node), 1);
100
- return '{' + _out.join(',') + indent + '}';
87
+ return '{' + out.join(',') + indent + '}'
101
88
  }
102
- }({
103
- '': obj
104
- }, '', obj, 0);
89
+ })({ '': obj }, '', obj, 0)
105
90
  }
106
91
 
107
92
  /*eslint-disable*/
108
- var ARRAYTYPE = '[object Array]';
109
- var OBJECTTYPE = '[object Object]';
110
- var FUNCTIONTYPE = '[object Function]';
111
- function diff(current, pre) {
112
- var result = {};
93
+ const ARRAYTYPE = '[object Array]';
94
+ const OBJECTTYPE = '[object Object]';
95
+ const FUNCTIONTYPE = '[object Function]';
96
+
97
+ function diff (current, pre) {
98
+ const result = {};
113
99
  syncKeys(current, pre);
114
100
  _diff(current, pre, '', result);
115
- return result;
101
+ return result
116
102
  }
117
- function syncKeys(current, pre) {
118
- if (current === pre) return;
119
- var rootCurrentType = type(current);
120
- var rootPreType = type(pre);
103
+
104
+ function syncKeys (current, pre) {
105
+ if (current === pre) return
106
+ const rootCurrentType = type(current);
107
+ const rootPreType = type(pre);
121
108
  if (rootCurrentType == OBJECTTYPE && rootPreType == OBJECTTYPE) {
122
109
  // if(Object.keys(current).length >= Object.keys(pre).length){
123
- for (var key in pre) {
124
- var currentValue = current[key];
110
+ for (let key in pre) {
111
+ const currentValue = current[key];
125
112
  if (currentValue === undefined) {
126
113
  current[key] = null;
127
114
  } else {
@@ -131,25 +118,26 @@
131
118
  // }
132
119
  } else if (rootCurrentType == ARRAYTYPE && rootPreType == ARRAYTYPE) {
133
120
  if (current.length >= pre.length) {
134
- pre.forEach(function (item, index) {
121
+ pre.forEach((item, index) => {
135
122
  syncKeys(current[index], item);
136
123
  });
137
124
  }
138
125
  }
139
126
  }
140
- function _diff(current, pre, path, result) {
141
- if (current === pre) return;
142
- var rootCurrentType = type(current);
143
- var rootPreType = type(pre);
127
+
128
+ function _diff (current, pre, path, result) {
129
+ if (current === pre) return
130
+ const rootCurrentType = type(current);
131
+ const rootPreType = type(pre);
144
132
  if (rootCurrentType == OBJECTTYPE) {
145
133
  if (rootPreType != OBJECTTYPE || Object.keys(current).length < Object.keys(pre).length) {
146
134
  setResult(result, path, current);
147
135
  } else {
148
- var _loop = function _loop(key) {
149
- var currentValue = current[key];
150
- var preValue = pre[key];
151
- var currentType = type(currentValue);
152
- var preType = type(preValue);
136
+ for (let key in current) {
137
+ const currentValue = current[key];
138
+ const preValue = pre[key];
139
+ const currentType = type(currentValue);
140
+ const preType = type(preValue);
153
141
  if (currentType != ARRAYTYPE && currentType != OBJECTTYPE) {
154
142
  if (currentValue != pre[key]) {
155
143
  setResult(result, (path == '' ? '' : path + '.') + key, currentValue);
@@ -161,7 +149,7 @@
161
149
  if (currentValue.length < preValue.length) {
162
150
  setResult(result, (path == '' ? '' : path + '.') + key, currentValue);
163
151
  } else {
164
- currentValue.forEach(function (item, index) {
152
+ currentValue.forEach((item, index) => {
165
153
  _diff(item, preValue[index], (path == '' ? '' : path + '.') + key + '[' + index + ']', result);
166
154
  });
167
155
  }
@@ -170,14 +158,11 @@
170
158
  if (preType != OBJECTTYPE || Object.keys(currentValue).length < Object.keys(preValue).length) {
171
159
  setResult(result, (path == '' ? '' : path + '.') + key, currentValue);
172
160
  } else {
173
- for (var subKey in currentValue) {
161
+ for (let subKey in currentValue) {
174
162
  _diff(currentValue[subKey], preValue[subKey], (path == '' ? '' : path + '.') + key + '.' + subKey, result);
175
163
  }
176
164
  }
177
165
  }
178
- };
179
- for (var key in current) {
180
- _loop(key);
181
166
  }
182
167
  }
183
168
  } else if (rootCurrentType == ARRAYTYPE) {
@@ -187,7 +172,7 @@
187
172
  if (current.length < pre.length) {
188
173
  setResult(result, path, current);
189
174
  } else {
190
- current.forEach(function (item, index) {
175
+ current.forEach((item, index) => {
191
176
  _diff(item, pre[index], path + '[' + index + ']', result);
192
177
  });
193
178
  }
@@ -196,890 +181,854 @@
196
181
  setResult(result, path, current);
197
182
  }
198
183
  }
199
- function setResult(result, k, v) {
184
+
185
+ function setResult (result, k, v) {
200
186
  if (type(v) != FUNCTIONTYPE) {
201
187
  result[k] = v;
202
188
  }
203
189
  }
204
- function type(obj) {
205
- return Object.prototype.toString.call(obj);
190
+
191
+ function type (obj) {
192
+ return Object.prototype.toString.call(obj)
206
193
  }
207
194
 
208
- var _lifecycleMap;
209
195
  var TaroLifeCycles;
210
196
  (function (TaroLifeCycles) {
211
- TaroLifeCycles["WillMount"] = "componentWillMount";
212
- TaroLifeCycles["DidMount"] = "componentDidMount";
213
- TaroLifeCycles["DidShow"] = "componentDidShow";
214
- TaroLifeCycles["DidHide"] = "componentDidHide";
215
- TaroLifeCycles["WillUnmount"] = "componentWillUnmount";
197
+ TaroLifeCycles["WillMount"] = "componentWillMount";
198
+ TaroLifeCycles["DidMount"] = "componentDidMount";
199
+ TaroLifeCycles["DidShow"] = "componentDidShow";
200
+ TaroLifeCycles["DidHide"] = "componentDidHide";
201
+ TaroLifeCycles["WillUnmount"] = "componentWillUnmount";
216
202
  })(TaroLifeCycles || (TaroLifeCycles = {}));
217
- var lifecycleMap = (_lifecycleMap = {}, _defineProperty__default["default"](_lifecycleMap, TaroLifeCycles.WillMount, ['created']), _defineProperty__default["default"](_lifecycleMap, TaroLifeCycles.DidMount, ['attached']), _defineProperty__default["default"](_lifecycleMap, TaroLifeCycles.DidShow, ['onShow']), _defineProperty__default["default"](_lifecycleMap, TaroLifeCycles.DidHide, ['onHide']), _defineProperty__default["default"](_lifecycleMap, TaroLifeCycles.WillUnmount, ['detached', 'onUnload']), _lifecycleMap);
218
- var lifecycles = new Set(['ready']);
219
- for (var key in lifecycleMap) {
220
- var lifecycle = lifecycleMap[key];
221
- lifecycle.forEach(function (l) {
222
- return lifecycles.add(l);
223
- });
203
+ const lifecycleMap = {
204
+ [TaroLifeCycles.WillMount]: ['created'],
205
+ [TaroLifeCycles.DidMount]: ['attached'],
206
+ [TaroLifeCycles.DidShow]: ['onShow'],
207
+ [TaroLifeCycles.DidHide]: ['onHide'],
208
+ [TaroLifeCycles.WillUnmount]: ['detached', 'onUnload']
209
+ };
210
+ const lifecycles = new Set(['ready']);
211
+ for (const key in lifecycleMap) {
212
+ const lifecycle = lifecycleMap[key];
213
+ lifecycle.forEach(l => lifecycles.add(l));
224
214
  }
225
- var uniquePageLifecycle = ['onPullDownRefresh', 'onReachBottom', 'onShareAppMessage', 'onShareTimeline', 'onAddToFavorites', 'onPageScroll', 'onResize', 'onTabItemTap'];
226
- var appOptions = ['onLaunch', 'onShow', 'onHide', 'onError', 'onPageNotFound', 'onUnhandledRejection', 'onThemeChange'];
215
+ const uniquePageLifecycle = [
216
+ 'onPullDownRefresh',
217
+ 'onReachBottom',
218
+ 'onShareAppMessage',
219
+ 'onShareTimeline',
220
+ 'onAddToFavorites',
221
+ 'onPageScroll',
222
+ 'onResize',
223
+ 'onTabItemTap'
224
+ ];
225
+ const appOptions = [
226
+ 'onLaunch',
227
+ 'onShow',
228
+ 'onHide',
229
+ 'onError',
230
+ 'onPageNotFound',
231
+ 'onUnhandledRejection',
232
+ 'onThemeChange'
233
+ ];
227
234
 
228
235
  /**
229
236
  * Simple bind, faster than native
230
237
  */
231
238
  function bind(fn /*: Function */, ctx /*: Object */) {
232
- if (!fn) return false;
233
- function boundFn(a) {
234
- var l /*: number */ = arguments.length;
235
- return l ? l > 1 ? fn.apply(ctx, arguments) : fn.call(ctx, a) : fn.call(ctx);
236
- }
237
- // record original fn length
238
- boundFn._length = fn.length;
239
- return boundFn;
239
+ if (!fn)
240
+ return false;
241
+ function boundFn(a) {
242
+ const l /*: number */ = arguments.length;
243
+ return l ? (l > 1 ? fn.apply(ctx, arguments) : fn.call(ctx, a)) : fn.call(ctx);
244
+ }
245
+ // record original fn length
246
+ boundFn._length = fn.length;
247
+ return boundFn;
240
248
  }
241
249
  function isEqual(obj1, obj2) {
242
- return JSON.stringify(obj1) === JSON.stringify(obj2);
250
+ return JSON.stringify(obj1) === JSON.stringify(obj2);
243
251
  }
244
252
  function safeGet(obj, propsArg, defaultValue) {
245
- if (!obj) {
246
- return defaultValue;
247
- }
248
- var props, prop;
249
- if (Array.isArray(propsArg)) {
250
- props = propsArg.slice(0);
251
- }
252
- if (typeof propsArg === 'string') {
253
- props = propsArg.replace(/\[(.+?)\]/g, '.$1');
254
- props = props.split('.');
255
- }
256
- if (_typeof__default["default"](propsArg) === 'symbol') {
257
- props = [propsArg];
258
- }
259
- if (!Array.isArray(props)) {
260
- throw new Error('props arg must be an array, a string or a symbol');
261
- }
262
- while (props.length) {
263
- prop = props.shift();
264
253
  if (!obj) {
265
- return defaultValue;
254
+ return defaultValue;
266
255
  }
267
- obj = obj[prop];
268
- if (obj === undefined) {
269
- return defaultValue;
256
+ let props, prop;
257
+ if (Array.isArray(propsArg)) {
258
+ props = propsArg.slice(0);
270
259
  }
271
- }
272
- return obj;
260
+ if (typeof propsArg === 'string') {
261
+ props = propsArg.replace(/\[(.+?)\]/g, '.$1');
262
+ props = props.split('.');
263
+ }
264
+ if (typeof propsArg === 'symbol') {
265
+ props = [propsArg];
266
+ }
267
+ if (!Array.isArray(props)) {
268
+ throw new Error('props arg must be an array, a string or a symbol');
269
+ }
270
+ while (props.length) {
271
+ prop = props.shift();
272
+ if (!obj) {
273
+ return defaultValue;
274
+ }
275
+ obj = obj[prop];
276
+ if (obj === undefined) {
277
+ return defaultValue;
278
+ }
279
+ }
280
+ return obj;
273
281
  }
274
282
  function safeSet(obj, props, value) {
275
- if (typeof props === 'string') {
276
- props = props.replace(/\[(.+?)\]/g, '.$1');
277
- props = props.split('.');
278
- }
279
- if (_typeof__default["default"](props) === 'symbol') {
280
- props = [props];
281
- }
282
- var lastProp = props.pop();
283
- if (!lastProp) {
284
- return false;
285
- }
286
- var thisProp;
287
- while (thisProp = props.shift()) {
288
- if (typeof obj[thisProp] === 'undefined') {
289
- obj[thisProp] = {};
283
+ if (typeof props === 'string') {
284
+ props = props.replace(/\[(.+?)\]/g, '.$1');
285
+ props = props.split('.');
290
286
  }
291
- // 直接按路径修改 this.state 可能会导致 nextProps 也被修改
292
- // 因此按路径寻找时,每一层都复制一遍
293
- if (Array.isArray(obj[thisProp])) {
294
- obj[thisProp] = _toConsumableArray__default["default"](obj[thisProp]);
295
- } else if (_typeof__default["default"](obj[thisProp]) === 'object') {
296
- obj[thisProp] = Object.assign({}, obj[thisProp]);
287
+ if (typeof props === 'symbol') {
288
+ props = [props];
297
289
  }
298
- obj = obj[thisProp];
299
- if (!obj || _typeof__default["default"](obj) !== 'object') {
300
- return false;
290
+ const lastProp = props.pop();
291
+ if (!lastProp) {
292
+ return false;
301
293
  }
302
- }
303
- obj[lastProp] = value;
304
- return true;
294
+ let thisProp;
295
+ while ((thisProp = props.shift())) {
296
+ if (typeof obj[thisProp] === 'undefined') {
297
+ obj[thisProp] = {};
298
+ }
299
+ // 直接按路径修改 this.state 可能会导致 nextProps 也被修改
300
+ // 因此按路径寻找时,每一层都复制一遍
301
+ if (Array.isArray(obj[thisProp])) {
302
+ obj[thisProp] = [...obj[thisProp]];
303
+ }
304
+ else if (typeof obj[thisProp] === 'object') {
305
+ obj[thisProp] = Object.assign({}, obj[thisProp]);
306
+ }
307
+ obj = obj[thisProp];
308
+ if (!obj || typeof obj !== 'object') {
309
+ return false;
310
+ }
311
+ }
312
+ obj[lastProp] = value;
313
+ return true;
305
314
  }
306
315
  function report(msg) {
307
- console.warn('[Taro Convert Warning] ' + msg);
316
+ console.warn('[Taro Convert Warning] ' + msg);
308
317
  }
309
- var nonsupport = new Map([['onError', '不支持 App 的 onError 生命周期方法。'], ['onPageNotFound', '不支持 App 的 onPageNotFound 生命周期方法。'], ['onUnhandledRejection', '不支持 App 的 onUnhandledRejection 生命周期方法。'], ['onThemeChange', '不支持 App 的 onThemeChange 生命周期方法。'], ['moved', '不支持自定义组件的 moved 生命周期。'], ['externalClasses', '不支持自定义组件的 externalClasses 功能。'], ['relations', '不支持自定义组件的 relations 功能。'], ['options', '不支持自定义组件的 options 功能。'], ['definitionFilter', '不支持自定义组件的 definitionFilter 功能。'], ['selectComponent', 'selectComponent 方法产生不到目标效果,请使用 React 的 ref 进行重构。'], ['selectAllComponents', 'selectAllComponents 方法产生不到目标效果,请使用 React 的 ref 进行重构。'], ['selectOwnerComponent', 'selectOwnerComponent 方法产生不到目标效果,请使用 React 语法重构。'], ['groupSetData', 'groupSetData 方法产生不到目标效果,请使用 React 语法重构。']]);
318
+ const nonsupport = new Map([
319
+ ['onError', '不支持 App 的 onError 生命周期方法。'],
320
+ ['onPageNotFound', '不支持 App 的 onPageNotFound 生命周期方法。'],
321
+ ['onUnhandledRejection', '不支持 App 的 onUnhandledRejection 生命周期方法。'],
322
+ ['onThemeChange', '不支持 App 的 onThemeChange 生命周期方法。'],
323
+ ['moved', '不支持自定义组件的 moved 生命周期。'],
324
+ ['externalClasses', '不支持自定义组件的 externalClasses 功能。'],
325
+ ['relations', '不支持自定义组件的 relations 功能。'],
326
+ ['options', '不支持自定义组件的 options 功能。'],
327
+ ['definitionFilter', '不支持自定义组件的 definitionFilter 功能。'],
328
+ ['selectComponent', 'selectComponent 方法产生不到目标效果,请使用 React 的 ref 进行重构。'],
329
+ ['selectAllComponents', 'selectAllComponents 方法产生不到目标效果,请使用 React 的 ref 进行重构。'],
330
+ ['selectOwnerComponent', 'selectOwnerComponent 方法产生不到目标效果,请使用 React 语法重构。'],
331
+ ['groupSetData', 'groupSetData 方法产生不到目标效果,请使用 React 语法重构。']
332
+ ]);
310
333
  function flattenBehaviors(behavior, behaviorMap) {
311
- if (typeof behavior === 'string') {
312
- return report("\u4E0D\u652F\u6301\u4F7F\u7528\u5185\u7F6E Behavior: [".concat(behavior, "]"));
313
- }
314
- var subBehaviors = behavior.behaviors;
315
- if (subBehaviors === null || subBehaviors === void 0 ? void 0 : subBehaviors.length) {
316
- subBehaviors.forEach(function (subBehavior) {
317
- return flattenBehaviors(subBehavior, behaviorMap);
318
- });
319
- }
320
- Object.keys(behavior).forEach(function (key) {
321
- // 不支持的属性
322
- if (nonsupport.has(key)) {
323
- var advise = nonsupport.get(key);
324
- return report(advise);
334
+ if (typeof behavior === 'string') {
335
+ return report(`不支持使用内置 Behavior: [${behavior}]`);
325
336
  }
326
- if (behaviorMap.has(key)) {
327
- var list = behaviorMap.get(key);
328
- var value = behavior[key];
329
- list.push(value);
337
+ const subBehaviors = behavior.behaviors;
338
+ if (subBehaviors === null || subBehaviors === void 0 ? void 0 : subBehaviors.length) {
339
+ subBehaviors.forEach(subBehavior => flattenBehaviors(subBehavior, behaviorMap));
330
340
  }
331
- });
341
+ Object.keys(behavior).forEach(key => {
342
+ // 不支持的属性
343
+ if (nonsupport.has(key)) {
344
+ const advise = nonsupport.get(key);
345
+ return report(advise);
346
+ }
347
+ if (behaviorMap.has(key)) {
348
+ const list = behaviorMap.get(key);
349
+ const value = behavior[key];
350
+ list.push(value);
351
+ }
352
+ });
332
353
  }
333
354
 
334
355
  /**
335
356
  * 该模块仅存放 convert 转换时用到的工具函数或变量
336
357
  */
337
- var cacheOptions = {
338
- cacheOptions: {},
339
- setOptionsToCache: function setOptionsToCache(options) {
340
- if (Object.keys(options).length !== 0) {
341
- this.cacheOptions = options;
358
+ const cacheOptions = {
359
+ cacheOptions: {},
360
+ setOptionsToCache: function (options) {
361
+ if (Object.keys(options).length !== 0) {
362
+ this.cacheOptions = options;
363
+ }
364
+ },
365
+ getOptionsFromCache: function () {
366
+ return this.cacheOptions;
342
367
  }
343
- },
344
- getOptionsFromCache: function getOptionsFromCache() {
345
- return this.cacheOptions;
346
- }
347
368
  };
348
369
  function toCamelCase(s) {
349
- var camel = '';
350
- var nextCap = false;
351
- for (var i = 0; i < s.length; i++) {
352
- if (s[i] !== '-') {
353
- camel += nextCap ? s[i].toUpperCase() : s[i];
354
- nextCap = false;
355
- } else {
356
- nextCap = true;
370
+ let camel = '';
371
+ let nextCap = false;
372
+ for (let i = 0; i < s.length; i++) {
373
+ if (s[i] !== '-') {
374
+ camel += nextCap ? s[i].toUpperCase() : s[i];
375
+ nextCap = false;
376
+ }
377
+ else {
378
+ nextCap = true;
379
+ }
357
380
  }
358
- }
359
- return camel;
381
+ return camel;
360
382
  }
361
- var convertToArray = function convertToArray(value, fn) {
362
- if (value instanceof Array) {
363
- return value.map(fn);
364
- } else if (typeof value === 'number') {
365
- return Array.from({
366
- length: value
367
- }, function (_, index) {
368
- return index;
369
- }).map(fn);
370
- } else if (typeof value === 'string') {
371
- return Array.from(value).map(fn);
372
- } else if (_typeof__default["default"](value) === 'object' && value !== null && Object.getPrototypeOf(value) === Object.prototype) {
373
- var result = Object.keys(value).map(function (item) {
374
- return fn(value[item], item);
375
- });
376
- return result;
377
- }
383
+ const convertToArray = function (value, fn) {
384
+ if (value instanceof Array) {
385
+ return value.map(fn);
386
+ }
387
+ else if (typeof value === 'number') {
388
+ return Array.from({
389
+ length: value
390
+ }, (_, index) => index).map(fn);
391
+ }
392
+ else if (typeof value === 'string') {
393
+ return Array.from(value).map(fn);
394
+ }
395
+ else if (typeof value === 'object' && value !== null && Object.getPrototypeOf(value) === Object.prototype) {
396
+ const result = Object.keys(value).map((item) => {
397
+ return fn(value[item], item);
398
+ });
399
+ return result;
400
+ }
378
401
  };
379
- var getTarget = function getTarget(target, Taro) {
380
- if (!target) {
381
- return {
382
- dataset: {}
383
- };
384
- }
385
- if (Taro.getEnv() === Taro.ENV_TYPE.HARMONYHYBRID || Taro.getEnv() === Taro.ENV_TYPE.WEB) {
386
- if (target.fullDataset) {
387
- return {
388
- dataset: target.fullDataset
389
- };
402
+ const getTarget = (target, Taro) => {
403
+ if (!target) {
404
+ return { dataset: {} };
390
405
  }
391
- var fullDataset = {};
392
- // 获取元素的所有属性
393
- var targetAttrKeys = Object.keys(target);
394
- // 遍历所有属性
395
- for (var i = 0; i < targetAttrKeys.length; i++) {
396
- if (targetAttrKeys[i].startsWith('data-')) {
397
- fullDataset[toCamelCase(targetAttrKeys[i].replace(/^data-/, '').toLowerCase())] = target[targetAttrKeys[i]];
398
- }
406
+ if (Taro.getEnv() === Taro.ENV_TYPE.HARMONYHYBRID || Taro.getEnv() === Taro.ENV_TYPE.WEB) {
407
+ if (target.fullDataset) {
408
+ return { dataset: target.fullDataset };
409
+ }
410
+ const fullDataset = {};
411
+ // 获取元素的所有属性
412
+ const targetAttrKeys = Object.keys(target);
413
+ // 遍历所有属性
414
+ for (let i = 0; i < targetAttrKeys.length; i++) {
415
+ if (targetAttrKeys[i].startsWith('data-')) {
416
+ fullDataset[toCamelCase(targetAttrKeys[i].replace(/^data-/, '').toLowerCase())] = target[targetAttrKeys[i]];
417
+ }
418
+ }
419
+ target.fullDataset = fullDataset;
420
+ return { dataset: fullDataset };
399
421
  }
400
- target.fullDataset = fullDataset;
401
- return {
402
- dataset: fullDataset
403
- };
404
- }
405
- return target;
422
+ return target;
406
423
  };
407
424
 
408
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
409
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
410
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
411
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf__default["default"](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default["default"](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default["default"](this, result); }; }
412
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
413
425
  function defineGetter(component, key, getter) {
414
- Object.defineProperty(component, key, {
415
- enumerable: true,
416
- configurable: true,
417
- get: function get() {
418
- if (getter === 'props') {
419
- return component.props;
420
- }
421
- return component.state;
422
- // return {
423
- // ...component.state,
424
- // ...component.props
425
- // }
426
- }
427
- });
426
+ Object.defineProperty(component, key, {
427
+ enumerable: true,
428
+ configurable: true,
429
+ get: () => {
430
+ if (getter === 'props') {
431
+ return component.props;
432
+ }
433
+ return component.state;
434
+ // return {
435
+ // ...component.state,
436
+ // ...component.props
437
+ // }
438
+ }
439
+ });
428
440
  }
429
-
430
441
  function propToState(newValue, _oldValue, key) {
431
- this.state[key] = newValue;
442
+ this.state[key] = newValue;
432
443
  }
433
444
  function isFunction(o) {
434
- return typeof o === 'function';
445
+ return typeof o === 'function';
435
446
  }
436
- function withWeapp(weappConf) {
437
- var isApp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
438
- if (_typeof__default["default"](weappConf) === 'object' && Object.keys(weappConf).length === 0) {
439
- report('withWeapp 请传入“App/页面/组件“的配置对象。如果原生写法使用了基类,请将基类组合后的配置对象传入,详情请参考文档。');
440
- }
441
- return function (ConnectComponent) {
442
- var _a;
443
- var behaviorMap = new Map([['properties', []], ['data', []], ['methods', []], ['created', []], ['attached', []], ['ready', []], ['detached', []], ['lifetimes', []]]);
444
- var behaviorProperties = {};
445
- if ((_a = weappConf.behaviors) === null || _a === void 0 ? void 0 : _a.length) {
446
- var behaviors = weappConf.behaviors;
447
- behaviors.forEach(function (behavior) {
448
- return flattenBehaviors(behavior, behaviorMap);
449
- });
450
- var propertiesList = behaviorMap.get('properties');
451
- if (propertiesList.length) {
452
- propertiesList.forEach(function (property) {
453
- Object.assign(behaviorProperties, property);
454
- });
455
- Object.keys(behaviorProperties).forEach(function (propName) {
456
- var propValue = behaviorProperties[propName];
457
- if (!weappConf.properties) {
458
- weappConf.properties = {};
459
- }
460
- if (!weappConf.properties.hasOwnProperty(propName)) {
461
- if (propValue && _typeof__default["default"](propValue) === 'object' && propValue.value) {
462
- propValue.value = clone(propValue.value);
463
- }
464
- weappConf.properties[propName] = propValue;
465
- }
466
- });
467
- }
447
+ function withWeapp(weappConf, isApp = false) {
448
+ if (typeof weappConf === 'object' && Object.keys(weappConf).length === 0) {
449
+ report('withWeapp 请传入“App/页面/组件“的配置对象。如果原生写法使用了基类,请将基类组合后的配置对象传入,详情请参考文档。');
468
450
  }
469
- var BaseComponent = /*#__PURE__*/function (_ConnectComponent) {
470
- _inherits__default["default"](BaseComponent, _ConnectComponent);
471
- var _super = _createSuper(BaseComponent);
472
- function BaseComponent(props) {
473
- var _this;
474
- _classCallCheck__default["default"](this, BaseComponent);
475
- _this = _super.call(this, props);
476
- _this._observeProps = [];
477
- // mixins 可以多次调用生命周期
478
- _this.willMounts = [];
479
- _this.didMounts = [];
480
- _this.didHides = [];
481
- _this.didShows = [];
482
- _this.willUnmounts = [];
483
- _this.eventDestroyList = [];
484
- _this.current = runtime.getCurrentInstance();
485
- _this.taroGlobalData = Object.create(null);
486
- _this.safeExecute = function (func) {
487
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
488
- args[_key - 1] = arguments[_key];
489
- }
490
- if (isFunction(func)) func.apply(_assertThisInitialized__default["default"](_this), args);
491
- };
492
- _this.setData = function (obj, callback) {
493
- var oldState;
494
- if (_this.observers && Object.keys(Object.keys(_this.observers))) {
495
- oldState = clone(_this.state);
496
- }
497
- Object.keys(obj).forEach(function (key) {
498
- safeSet(_this.state, key, obj[key]);
499
- });
500
- _this.setState(_this.state, function () {
501
- _this.triggerObservers(_this.state, oldState);
502
- if (callback) {
503
- callback.call(_assertThisInitialized__default["default"](_this));
504
- }
505
- });
506
- };
507
- _this.triggerEvent = function (eventName, detail, options) {
508
- if (options) {
509
- report('triggerEvent 不支持事件选项。');
510
- }
511
- // eventName support kebab case
512
- if (eventName.match(/[a-z]+-[a-z]+/g)) {
513
- eventName = eventName.replace(/-[a-z]/g, function (match) {
514
- return match[1].toUpperCase();
515
- });
516
- }
517
- var props = _this.props;
518
- var dataset = {};
519
- for (var key in props) {
520
- if (!key.startsWith('data-')) continue;
521
- dataset[key.replace(/^data-/, '')] = props[key];
522
- }
523
- var func = props["on".concat(eventName[0].toUpperCase()).concat(eventName.slice(1))];
524
- if (isFunction(func)) {
525
- func.call(_assertThisInitialized__default["default"](_this), {
526
- type: eventName,
527
- detail: detail,
528
- target: {
529
- id: props.id || '',
530
- dataset: dataset
531
- },
532
- currentTarget: {
533
- id: props.id || '',
534
- dataset: dataset
535
- }
536
- });
537
- }
538
- };
539
- _this.hasBehavior = _this.componentMethodsProxy('hasBehavior');
540
- _this.createSelectorQuery = _this.componentMethodsProxy('createSelectorQuery');
541
- _this.createIntersectionObserver = _this.componentMethodsProxy('createIntersectionObserver');
542
- _this.createMediaQueryObserver = _this.componentMethodsProxy('createMediaQueryObserver');
543
- _this.getRelationNodes = _this.componentMethodsProxy('getRelationNodes');
544
- _this.getTabBar = _this.componentMethodsProxy('getTabBar');
545
- _this.getPageId = _this.componentMethodsProxy('getPageId');
546
- _this.animate = _this.componentMethodsProxy('animate');
547
- _this.clearAnimation = _this.componentMethodsProxy('clearAnimation');
548
- _this.setUpdatePerformanceListener = _this.componentMethodsProxy('setUpdatePerformanceListener');
549
- _this.state = _this.state || {};
550
- _this.init(weappConf);
551
- defineGetter(_assertThisInitialized__default["default"](_this), 'data', 'state');
552
- defineGetter(_assertThisInitialized__default["default"](_this), 'properties', 'props');
553
- return _this;
554
- }
555
- _createClass__default["default"](BaseComponent, [{
556
- key: "initProps",
557
- value: function initProps(props) {
558
- var properties = {};
559
- for (var propKey in props) {
560
- if (props.hasOwnProperty(propKey)) {
561
- var propValue = props[propKey];
562
- // propValue 可能是 null, 构造函数, 对象
563
- var observers = [propToState];
564
- if (propValue === null || propValue === undefined) {
565
- // propValue为null、undefined情况
566
- properties[propKey] = null;
567
- } else if (isFunction(propValue)) {
568
- // propValue为Function,即Array、String、Boolean等情况时
569
- if (propValue.name === 'Array') {
570
- properties[propKey] = [];
571
- } else if (propValue.name === 'String') {
572
- properties[propKey] = '';
573
- } else if (propValue.name === 'Boolean') {
574
- properties[propKey] = false;
575
- } else if (propValue.name === 'Number') {
576
- properties[propKey] = 0;
577
- } else {
578
- properties[propKey] = null;
579
- }
580
- } else if (_typeof__default["default"](propValue) === 'object') {
581
- // propValue为对象时
582
- properties[propKey] = propValue.value;
583
- if (propValue.observer) {
584
- observers.push(propValue.observer);
585
- }
586
- } else {
587
- properties[propKey] = null;
588
- }
589
- this._observeProps.push({
590
- name: propKey,
591
- observers: observers
592
- });
451
+ return (ConnectComponent) => {
452
+ var _a;
453
+ const behaviorMap = new Map([
454
+ ['properties', []],
455
+ ['data', []],
456
+ ['methods', []],
457
+ ['created', []],
458
+ ['attached', []],
459
+ ['ready', []],
460
+ ['detached', []],
461
+ ['lifetimes', []]
462
+ ]);
463
+ const behaviorProperties = {};
464
+ if ((_a = weappConf.behaviors) === null || _a === void 0 ? void 0 : _a.length) {
465
+ const { behaviors } = weappConf;
466
+ behaviors.forEach(behavior => flattenBehaviors(behavior, behaviorMap));
467
+ const propertiesList = behaviorMap.get('properties');
468
+ if (propertiesList.length) {
469
+ propertiesList.forEach(property => {
470
+ Object.assign(behaviorProperties, property);
471
+ });
472
+ Object.keys(behaviorProperties).forEach(propName => {
473
+ const propValue = behaviorProperties[propName];
474
+ if (!weappConf.properties) {
475
+ weappConf.properties = {};
476
+ }
477
+ if (!weappConf.properties.hasOwnProperty(propName)) {
478
+ if (propValue && typeof propValue === 'object' && propValue.value) {
479
+ propValue.value = clone(propValue.value);
480
+ }
481
+ weappConf.properties[propName] = propValue;
482
+ }
483
+ });
593
484
  }
594
- }
595
- this.state = Object.assign(Object.assign({}, properties), this.state);
596
485
  }
597
- }, {
598
- key: "init",
599
- value: function init(options) {
600
- var _this2 = this;
601
- var _a, _b, _c;
602
- // 处理 Behaviors
603
- if ((_a = options.behaviors) === null || _a === void 0 ? void 0 : _a.length) {
604
- var _iterator = _createForOfIteratorHelper(behaviorMap.entries()),
605
- _step;
606
- try {
607
- var _loop = function _loop() {
608
- var _step$value = _slicedToArray__default["default"](_step.value, 2),
609
- key = _step$value[0],
610
- list = _step$value[1];
611
- switch (key) {
612
- case 'created':
613
- case 'attached':
614
- case 'detached':
615
- case 'ready':
616
- list.forEach(function (fn) {
617
- return _this2.initLifeCycles(key, fn);
486
+ class BaseComponent extends ConnectComponent {
487
+ constructor(props) {
488
+ super(props);
489
+ this._observeProps = [];
490
+ // mixins 可以多次调用生命周期
491
+ this.willMounts = [];
492
+ this.didMounts = [];
493
+ this.didHides = [];
494
+ this.didShows = [];
495
+ this.willUnmounts = [];
496
+ this.eventDestroyList = [];
497
+ this.current = runtime.getCurrentInstance();
498
+ this.taroGlobalData = Object.create(null);
499
+ this.safeExecute = (func, ...args) => {
500
+ if (isFunction(func))
501
+ func.apply(this, args);
502
+ };
503
+ this.setData = (obj, callback) => {
504
+ let oldState;
505
+ if (this.observers && Object.keys(Object.keys(this.observers))) {
506
+ oldState = clone(this.state);
507
+ }
508
+ Object.keys(obj).forEach(key => {
509
+ safeSet(this.state, key, obj[key]);
618
510
  });
619
- break;
620
- }
621
- };
622
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
623
- _loop();
624
- }
625
- } catch (err) {
626
- _iterator.e(err);
627
- } finally {
628
- _iterator.f();
629
- }
630
- }
631
- for (var confKey in options) {
632
- // 不支持的属性
633
- if (nonsupport.has(confKey)) {
634
- var advise = nonsupport.get(confKey);
635
- report(advise);
511
+ this.setState(this.state, () => {
512
+ this.triggerObservers(this.state, oldState);
513
+ if (callback) {
514
+ callback.call(this);
515
+ }
516
+ });
517
+ };
518
+ this.triggerEvent = (eventName, detail, options) => {
519
+ if (options) {
520
+ report('triggerEvent 不支持事件选项。');
521
+ }
522
+ // eventName support kebab case
523
+ if (eventName.match(/[a-z]+-[a-z]+/g)) {
524
+ eventName = eventName.replace(/-[a-z]/g, function (match) {
525
+ return match[1].toUpperCase();
526
+ });
527
+ }
528
+ const props = this.props;
529
+ const dataset = {};
530
+ for (const key in props) {
531
+ if (!key.startsWith('data-'))
532
+ continue;
533
+ dataset[key.replace(/^data-/, '')] = props[key];
534
+ }
535
+ const func = props[`on${eventName[0].toUpperCase()}${eventName.slice(1)}`];
536
+ if (isFunction(func)) {
537
+ func.call(this, {
538
+ type: eventName,
539
+ detail,
540
+ target: {
541
+ id: props.id || '',
542
+ dataset
543
+ },
544
+ currentTarget: {
545
+ id: props.id || '',
546
+ dataset
547
+ }
548
+ });
549
+ }
550
+ };
551
+ this.hasBehavior = this.componentMethodsProxy('hasBehavior');
552
+ this.createSelectorQuery = this.componentMethodsProxy('createSelectorQuery');
553
+ this.createIntersectionObserver = this.componentMethodsProxy('createIntersectionObserver');
554
+ this.createMediaQueryObserver = this.componentMethodsProxy('createMediaQueryObserver');
555
+ this.getRelationNodes = this.componentMethodsProxy('getRelationNodes');
556
+ this.getTabBar = this.componentMethodsProxy('getTabBar');
557
+ this.getPageId = this.componentMethodsProxy('getPageId');
558
+ this.animate = this.componentMethodsProxy('animate');
559
+ this.clearAnimation = this.componentMethodsProxy('clearAnimation');
560
+ this.setUpdatePerformanceListener = this.componentMethodsProxy('setUpdatePerformanceListener');
561
+ this.state = this.state || {};
562
+ this.init(weappConf);
563
+ defineGetter(this, 'data', 'state');
564
+ defineGetter(this, 'properties', 'props');
565
+ this.initComputed(weappConf);
636
566
  }
637
- var confValue = options[confKey];
638
- switch (confKey) {
639
- case 'behaviors':
640
- break;
641
- case 'data':
642
- {
643
- if (isApp) {
644
- this[confKey] = confValue;
645
- if (!appOptions.includes(confKey)) {
646
- this.defineProperty(this.taroGlobalData, confKey, this);
567
+ initProps(props) {
568
+ const properties = {};
569
+ for (const propKey in props) {
570
+ if (props.hasOwnProperty(propKey)) {
571
+ const propValue = props[propKey];
572
+ // propValue 可能是 null, 构造函数, 对象
573
+ const observers = [propToState];
574
+ if (propValue === null || propValue === undefined) { // propValue为null、undefined情况
575
+ properties[propKey] = null;
576
+ }
577
+ else if (isFunction(propValue)) { // propValue为Function,即Array、String、Boolean等情况时
578
+ if (propValue.name === 'Array') {
579
+ properties[propKey] = [];
580
+ }
581
+ else if (propValue.name === 'String') {
582
+ properties[propKey] = '';
583
+ }
584
+ else if (propValue.name === 'Boolean') {
585
+ properties[propKey] = false;
586
+ }
587
+ else if (propValue.name === 'Number') {
588
+ properties[propKey] = 0;
589
+ }
590
+ else {
591
+ properties[propKey] = null;
592
+ }
593
+ }
594
+ else if (typeof propValue === 'object') { // propValue为对象时
595
+ properties[propKey] = propValue.value;
596
+ if (propValue.observer) {
597
+ observers.push(propValue.observer);
598
+ }
599
+ }
600
+ else {
601
+ properties[propKey] = null;
602
+ }
603
+ this._observeProps.push({
604
+ name: propKey,
605
+ observers: observers
606
+ });
647
607
  }
648
- } else {
649
- this.state = Object.assign(Object.assign({}, confValue), this.state);
650
- }
651
- break;
652
608
  }
653
- case 'properties':
654
- this.initProps(Object.assign(behaviorProperties, confValue));
655
- break;
656
- case 'methods':
657
- for (var key in confValue) {
658
- var method = confValue[key];
659
- this[key] = bind(method, this);
609
+ this.state = Object.assign(Object.assign({}, properties), this.state);
610
+ }
611
+ init(options) {
612
+ var _a, _b, _c;
613
+ // 处理 Behaviors
614
+ if ((_a = options.behaviors) === null || _a === void 0 ? void 0 : _a.length) {
615
+ for (const [key, list] of behaviorMap.entries()) {
616
+ switch (key) {
617
+ case 'created':
618
+ case 'attached':
619
+ case 'detached':
620
+ case 'ready':
621
+ list.forEach(fn => this.initLifeCycles(key, fn));
622
+ break;
623
+ }
624
+ }
660
625
  }
661
- break;
662
- case 'lifetimes':
663
- for (var _key2 in confValue) {
664
- this.initLifeCycles(_key2, confValue[_key2]);
626
+ for (const confKey in options) {
627
+ // 不支持的属性
628
+ if (nonsupport.has(confKey)) {
629
+ const advise = nonsupport.get(confKey);
630
+ report(advise);
631
+ }
632
+ const confValue = options[confKey];
633
+ switch (confKey) {
634
+ case 'behaviors':
635
+ break;
636
+ case 'data': {
637
+ if (isApp) {
638
+ this[confKey] = confValue;
639
+ if (!appOptions.includes(confKey)) {
640
+ this.defineProperty(this.taroGlobalData, confKey, this);
641
+ }
642
+ }
643
+ else {
644
+ this.state = Object.assign(Object.assign({}, confValue), this.state);
645
+ }
646
+ break;
647
+ }
648
+ case 'properties':
649
+ this.initProps(Object.assign(behaviorProperties, confValue));
650
+ break;
651
+ case 'methods':
652
+ this.methods = confValue;
653
+ for (const key in confValue) {
654
+ const method = confValue[key];
655
+ this[key] = bind(method, this);
656
+ }
657
+ break;
658
+ case 'lifetimes':
659
+ for (const key in confValue) {
660
+ this.initLifeCycles(key, confValue[key]);
661
+ }
662
+ break;
663
+ case 'pageLifetimes':
664
+ for (const key in confValue) {
665
+ const cb = confValue[key];
666
+ switch (key) {
667
+ case 'show': {
668
+ this.initLifeCycleListener('show', cb);
669
+ break;
670
+ }
671
+ case 'hide': {
672
+ this.initLifeCycleListener('hide', cb);
673
+ break;
674
+ }
675
+ case 'resize': {
676
+ report('不支持组件所在页面的生命周期 pageLifetimes.resize。');
677
+ break;
678
+ }
679
+ }
680
+ }
681
+ break;
682
+ default:
683
+ if (lifecycles.has(confKey)) {
684
+ // 优先使用 lifetimes 中定义的生命周期
685
+ if ((_b = options.lifetimes) === null || _b === void 0 ? void 0 : _b[confKey]) {
686
+ break;
687
+ }
688
+ const lifecycle = options[confKey];
689
+ this.initLifeCycles(confKey, lifecycle);
690
+ }
691
+ else if (isFunction(confValue)) {
692
+ this[confKey] = bind(confValue, this);
693
+ if (isApp && !appOptions.includes(confKey)) {
694
+ this.defineProperty(this.taroGlobalData, confKey, this);
695
+ }
696
+ // 原生页面和 Taro 页面中共计只能定义一次的生命周期
697
+ if (uniquePageLifecycle.includes(confKey) && ConnectComponent.prototype[confKey]) {
698
+ report(`生命周期 ${confKey} 已在原生部分进行定义,React 部分的定义将不会被执行。`);
699
+ }
700
+ }
701
+ else {
702
+ this[confKey] = confValue;
703
+ if (isApp && !appOptions.includes(confKey)) {
704
+ this.defineProperty(this.taroGlobalData, confKey, this);
705
+ }
706
+ }
707
+ break;
708
+ }
665
709
  }
666
- break;
667
- case 'pageLifetimes':
668
- for (var _key3 in confValue) {
669
- var cb = confValue[_key3];
670
- switch (_key3) {
671
- case 'show':
672
- {
673
- this.initLifeCycleListener('show', cb);
674
- break;
675
- }
676
- case 'hide':
677
- {
678
- this.initLifeCycleListener('hide', cb);
679
- break;
680
- }
681
- case 'resize':
682
- {
683
- report('不支持组件所在页面的生命周期 pageLifetimes.resize。');
684
- break;
685
- }
686
- }
710
+ // 处理 Behaviors
711
+ if ((_c = options.behaviors) === null || _c === void 0 ? void 0 : _c.length) {
712
+ const behaviorData = {};
713
+ const methods = {};
714
+ for (const [key, list] of behaviorMap.entries()) {
715
+ switch (key) {
716
+ case 'data':
717
+ [...list, this.state].forEach((dataObject, index) => {
718
+ Object.keys(dataObject).forEach(dataKey => {
719
+ const value = dataObject[dataKey];
720
+ const preValue = behaviorData[dataKey];
721
+ const valueType = typeof value;
722
+ const preValueType = typeof preValue;
723
+ if (valueType === 'object') {
724
+ if (!value) {
725
+ behaviorData[dataKey] = value;
726
+ }
727
+ else if (preValueType !== 'object' || !preValueType || Array.isArray(value)) {
728
+ behaviorData[dataKey] = index === list.length ? value : clone(value);
729
+ }
730
+ else {
731
+ const newVal = Object.assign({}, preValue, value);
732
+ behaviorData[dataKey] = index === list.length ? newVal : clone(newVal);
733
+ }
734
+ }
735
+ else {
736
+ behaviorData[dataKey] = value;
737
+ }
738
+ });
739
+ });
740
+ this.state = behaviorData;
741
+ break;
742
+ case 'methods':
743
+ list.forEach(methodsObject => {
744
+ Object.assign(methods, methodsObject);
745
+ });
746
+ Object.keys(methods).forEach(methodName => {
747
+ if (!this[methodName]) {
748
+ const method = methods[methodName];
749
+ this[methodName] = bind(method, this);
750
+ }
751
+ });
752
+ break;
753
+ case 'lifetimes':
754
+ list.forEach(lifetimesObject => {
755
+ for (const key in lifetimesObject) {
756
+ this.initLifeCycles(key, lifetimesObject[key]);
757
+ }
758
+ });
759
+ break;
760
+ }
761
+ }
687
762
  }
688
- break;
689
- default:
690
- if (lifecycles.has(confKey)) {
691
- // 优先使用 lifetimes 中定义的生命周期
692
- if ((_b = options.lifetimes) === null || _b === void 0 ? void 0 : _b[confKey]) {
693
- break;
694
- }
695
- var lifecycle = options[confKey];
696
- this.initLifeCycles(confKey, lifecycle);
697
- } else if (isFunction(confValue)) {
698
- this[confKey] = bind(confValue, this);
699
- if (isApp && !appOptions.includes(confKey)) {
700
- this.defineProperty(this.taroGlobalData, confKey, this);
701
- }
702
- // 原生页面和 Taro 页面中共计只能定义一次的生命周期
703
- if (uniquePageLifecycle.includes(confKey) && ConnectComponent.prototype[confKey]) {
704
- report("\u751F\u547D\u5468\u671F ".concat(confKey, " \u5DF2\u5728\u539F\u751F\u90E8\u5206\u8FDB\u884C\u5B9A\u4E49\uFF0CReact \u90E8\u5206\u7684\u5B9A\u4E49\u5C06\u4E0D\u4F1A\u88AB\u6267\u884C\u3002"));
705
- }
706
- } else {
707
- this[confKey] = confValue;
708
- if (isApp && !appOptions.includes(confKey)) {
709
- this.defineProperty(this.taroGlobalData, confKey, this);
710
- }
763
+ }
764
+ initComputed(weappConf) {
765
+ // 处理 computed
766
+ if (weappConf.computed) {
767
+ const computed = weappConf.computed;
768
+ for (const key in computed) {
769
+ const getter = computed[key];
770
+ if (isFunction(getter)) {
771
+ Object.defineProperty(this.data, key, {
772
+ get: () => {
773
+ // 每次访问 this.object.data[name] 时,都执行 computed[name]()
774
+ return getter.call(Object.assign(Object.assign({}, this.state), this.methods));
775
+ },
776
+ enumerable: true, // 这将确保属性是可枚举的,如果你希望它出现在 for...in 循环中
777
+ configurable: true // 这将确保属性是可配置的,比如可以被删除
778
+ });
779
+ }
780
+ else {
781
+ report('computed 属性值必须是函数。');
782
+ }
783
+ }
711
784
  }
712
- break;
713
785
  }
714
- }
715
- // 处理 Behaviors
716
- if ((_c = options.behaviors) === null || _c === void 0 ? void 0 : _c.length) {
717
- var behaviorData = {};
718
- var methods = {};
719
- var _iterator2 = _createForOfIteratorHelper(behaviorMap.entries()),
720
- _step2;
721
- try {
722
- var _loop2 = function _loop2() {
723
- var _step2$value = _slicedToArray__default["default"](_step2.value, 2),
724
- key = _step2$value[0],
725
- list = _step2$value[1];
726
- switch (key) {
727
- case 'data':
728
- [].concat(_toConsumableArray__default["default"](list), [_this2.state]).forEach(function (dataObject, index) {
729
- Object.keys(dataObject).forEach(function (dataKey) {
730
- var value = dataObject[dataKey];
731
- var preValue = behaviorData[dataKey];
732
- var valueType = _typeof__default["default"](value);
733
- var preValueType = _typeof__default["default"](preValue);
734
- if (valueType === 'object') {
735
- if (!value) {
736
- behaviorData[dataKey] = value;
737
- } else if (preValueType !== 'object' || !preValueType || Array.isArray(value)) {
738
- behaviorData[dataKey] = index === list.length ? value : clone(value);
739
- } else {
740
- var newVal = Object.assign({}, preValue, value);
741
- behaviorData[dataKey] = index === list.length ? newVal : clone(newVal);
742
- }
743
- } else {
744
- behaviorData[dataKey] = value;
786
+ initLifeCycles(lifecycleName, lifecycle) {
787
+ // 不支持的生命周期
788
+ if (nonsupport.has(lifecycleName)) {
789
+ const advise = nonsupport.get(lifecycleName);
790
+ return report(advise);
791
+ }
792
+ if (lifecycleName === 'ready') {
793
+ // 如果组件是延时渲染的,页面 onReady 的事件已经 emit 了,因此使用 componentDidMount + nextTick 模拟
794
+ if (this.current.page.onReady.called) {
795
+ this.didMounts.push(function (...args) {
796
+ taro.nextTick(() => {
797
+ if (isFunction(lifecycle)) {
798
+ lifecycle.apply(this, args);
799
+ }
800
+ });
801
+ });
802
+ }
803
+ else {
804
+ this.initLifeCycleListener('ready', lifecycle);
805
+ }
806
+ }
807
+ else {
808
+ for (const lifecycleKey in lifecycleMap) {
809
+ const cycleNames = lifecycleMap[lifecycleKey];
810
+ if (cycleNames.indexOf(lifecycleName) !== -1) {
811
+ switch (lifecycleKey) {
812
+ case TaroLifeCycles.DidHide:
813
+ this.didHides.push(lifecycle);
814
+ break;
815
+ case TaroLifeCycles.DidMount:
816
+ this.didMounts.push(lifecycle);
817
+ break;
818
+ case TaroLifeCycles.DidShow:
819
+ this.didShows.push(lifecycle);
820
+ break;
821
+ case TaroLifeCycles.WillMount:
822
+ this.willMounts.push(lifecycle);
823
+ break;
824
+ case TaroLifeCycles.WillUnmount:
825
+ this.willUnmounts.push(lifecycle);
826
+ break;
827
+ }
745
828
  }
746
- });
747
- });
748
- _this2.state = behaviorData;
749
- break;
750
- case 'methods':
751
- list.forEach(function (methodsObject) {
752
- Object.assign(methods, methodsObject);
753
- });
754
- Object.keys(methods).forEach(function (methodName) {
755
- if (!_this2[methodName]) {
756
- var _method = methods[methodName];
757
- _this2[methodName] = bind(_method, _this2);
758
- }
759
- });
760
- break;
761
- case 'lifetimes':
762
- list.forEach(function (lifetimesObject) {
763
- for (var _key4 in lifetimesObject) {
764
- _this2.initLifeCycles(_key4, lifetimesObject[_key4]);
765
- }
766
- });
767
- break;
768
- default:
769
- break;
829
+ }
830
+ }
831
+ // mixins 不会覆盖已经设置的生命周期,加入到 this 是为了形如 this.created() 的调用
832
+ if (!isFunction(this[lifecycleName])) {
833
+ this[lifecycleName] = lifecycle;
770
834
  }
771
- };
772
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
773
- _loop2();
774
- }
775
- } catch (err) {
776
- _iterator2.e(err);
777
- } finally {
778
- _iterator2.f();
779
835
  }
780
- }
781
- }
782
- }, {
783
- key: "initLifeCycles",
784
- value: function initLifeCycles(lifecycleName, lifecycle) {
785
- // 不支持的生命周期
786
- if (nonsupport.has(lifecycleName)) {
787
- var advise = nonsupport.get(lifecycleName);
788
- return report(advise);
789
- }
790
- if (lifecycleName === 'ready') {
791
- // 如果组件是延时渲染的,页面 onReady 的事件已经 emit 了,因此使用 componentDidMount + nextTick 模拟
792
- if (this.current.page.onReady.called) {
793
- this.didMounts.push(function () {
794
- var _this3 = this;
795
- for (var _len2 = arguments.length, args = new Array(_len2), _key5 = 0; _key5 < _len2; _key5++) {
796
- args[_key5] = arguments[_key5];
836
+ initLifeCycleListener(name, cb) {
837
+ // 组件的 ready、show、hide 需要利用页面事件触发
838
+ const { router } = this.current;
839
+ const lifecycleName = `on${name[0].toUpperCase()}${name.slice(1)}`;
840
+ cb = cb.bind(this);
841
+ (router === null || router === void 0 ? void 0 : router[lifecycleName]) && taro.eventCenter.on(router[lifecycleName], cb);
842
+ // unMount 时需要取消事件监听
843
+ this.eventDestroyList.push(() => taro.eventCenter.off(router[lifecycleName], cb));
844
+ }
845
+ executeLifeCycles(funcs, ...args) {
846
+ for (let i = 0; i < funcs.length; i++) {
847
+ const func = funcs[i];
848
+ this.safeExecute(func, ...args);
797
849
  }
798
- taro.nextTick(function () {
799
- if (isFunction(lifecycle)) {
800
- lifecycle.apply(_this3, args);
801
- }
850
+ }
851
+ triggerPropertiesObservers(prevProps, nextProps) {
852
+ this._observeProps.forEach(({ name: key, observers }) => {
853
+ const prop = prevProps === null || prevProps === void 0 ? void 0 : prevProps[key];
854
+ const nextProp = nextProps[key];
855
+ // 小程序是深比较不同之后才 trigger observer
856
+ if (!isEqual(prop, nextProp)) {
857
+ observers.forEach((observer) => {
858
+ if (typeof observer === 'string') {
859
+ const ob = this[observer];
860
+ if (isFunction(ob)) {
861
+ ob.call(this, nextProp, prop, key);
862
+ }
863
+ }
864
+ else if (isFunction(observer)) {
865
+ observer.call(this, nextProp, prop, key);
866
+ }
867
+ });
868
+ }
802
869
  });
803
- });
804
- } else {
805
- this.initLifeCycleListener('ready', lifecycle);
806
870
  }
807
- } else {
808
- for (var lifecycleKey in lifecycleMap) {
809
- var cycleNames = lifecycleMap[lifecycleKey];
810
- if (cycleNames.indexOf(lifecycleName) !== -1) {
811
- switch (lifecycleKey) {
812
- case TaroLifeCycles.DidHide:
813
- this.didHides.push(lifecycle);
814
- break;
815
- case TaroLifeCycles.DidMount:
816
- this.didMounts.push(lifecycle);
817
- break;
818
- case TaroLifeCycles.DidShow:
819
- this.didShows.push(lifecycle);
820
- break;
821
- case TaroLifeCycles.WillMount:
822
- this.willMounts.push(lifecycle);
823
- break;
824
- case TaroLifeCycles.WillUnmount:
825
- this.willUnmounts.push(lifecycle);
826
- break;
871
+ triggerObservers(current, prev) {
872
+ const observers = this.observers;
873
+ if (observers == null) {
874
+ return;
827
875
  }
828
- }
829
- }
830
- }
831
- // mixins 不会覆盖已经设置的生命周期,加入到 this 是为了形如 this.created() 的调用
832
- if (!isFunction(this[lifecycleName])) {
833
- this[lifecycleName] = lifecycle;
834
- }
835
- }
836
- }, {
837
- key: "initLifeCycleListener",
838
- value: function initLifeCycleListener(name, cb) {
839
- // 组件的 ready、show、hide 需要利用页面事件触发
840
- var router = this.current.router;
841
- var lifecycleName = "on".concat(name[0].toUpperCase()).concat(name.slice(1));
842
- cb = cb.bind(this);
843
- (router === null || router === void 0 ? void 0 : router[lifecycleName]) && taro.eventCenter.on(router[lifecycleName], cb);
844
- // unMount 时需要取消事件监听
845
- this.eventDestroyList.push(function () {
846
- return taro.eventCenter.off(router[lifecycleName], cb);
847
- });
848
- }
849
- }, {
850
- key: "executeLifeCycles",
851
- value: function executeLifeCycles(funcs) {
852
- for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key6 = 1; _key6 < _len3; _key6++) {
853
- args[_key6 - 1] = arguments[_key6];
854
- }
855
- for (var i = 0; i < funcs.length; i++) {
856
- var func = funcs[i];
857
- this.safeExecute.apply(this, [func].concat(args));
858
- }
859
- }
860
- }, {
861
- key: "triggerPropertiesObservers",
862
- value: function triggerPropertiesObservers(prevProps, nextProps) {
863
- var _this4 = this;
864
- this._observeProps.forEach(function (_ref) {
865
- var key = _ref.name,
866
- observers = _ref.observers;
867
- var prop = prevProps === null || prevProps === void 0 ? void 0 : prevProps[key];
868
- var nextProp = nextProps[key];
869
- // 小程序是深比较不同之后才 trigger observer
870
- if (!isEqual(prop, nextProp)) {
871
- observers.forEach(function (observer) {
872
- if (typeof observer === 'string') {
873
- var ob = _this4[observer];
874
- if (isFunction(ob)) {
875
- ob.call(_this4, nextProp, prop, key);
876
- }
877
- } else if (isFunction(observer)) {
878
- observer.call(_this4, nextProp, prop, key);
876
+ if (Object.keys(observers).length === 0) {
877
+ return;
878
+ }
879
+ const result = diff(current, prev);
880
+ const resultKeys = Object.keys(result);
881
+ if (resultKeys.length === 0) {
882
+ return;
883
+ }
884
+ for (const observerKey in observers) {
885
+ if (/\*\*/.test(observerKey)) {
886
+ report('数据监听器 observers 不支持使用通配符 **。');
887
+ continue;
888
+ }
889
+ const keys = observerKey.split(',').map(k => k.trim());
890
+ let isModified = false;
891
+ for (let i = 0; i < keys.length; i++) {
892
+ const key = keys[i];
893
+ for (let j = 0; j < resultKeys.length; j++) {
894
+ const resultKey = resultKeys[j];
895
+ if (resultKey.startsWith(key) ||
896
+ (key.startsWith(resultKey) && key.endsWith(']'))) {
897
+ isModified = true;
898
+ }
899
+ }
900
+ }
901
+ if (isModified) {
902
+ observers[observerKey].apply(this, keys.map(key => safeGet(current, key)));
903
+ }
879
904
  }
880
- });
881
905
  }
882
- });
883
- }
884
- }, {
885
- key: "triggerObservers",
886
- value: function triggerObservers(current, prev) {
887
- var observers = this.observers;
888
- if (observers == null) {
889
- return;
890
- }
891
- if (Object.keys(observers).length === 0) {
892
- return;
893
- }
894
- var result = diff(current, prev);
895
- var resultKeys = Object.keys(result);
896
- if (resultKeys.length === 0) {
897
- return;
898
- }
899
- for (var observerKey in observers) {
900
- if (/\*\*/.test(observerKey)) {
901
- report('数据监听器 observers 不支持使用通配符 **。');
902
- continue;
906
+ defineProperty(target, key, data) {
907
+ Object.defineProperty(target, key, {
908
+ configurable: true,
909
+ enumerable: true,
910
+ set(value) {
911
+ data[key] = value;
912
+ },
913
+ get() {
914
+ return data[key];
915
+ }
916
+ });
903
917
  }
904
- var keys = observerKey.split(',').map(function (k) {
905
- return k.trim();
906
- });
907
- var isModified = false;
908
- for (var i = 0; i < keys.length; i++) {
909
- var key = keys[i];
910
- for (var j = 0; j < resultKeys.length; j++) {
911
- var resultKey = resultKeys[j];
912
- if (resultKey.startsWith(key) || key.startsWith(resultKey) && key.endsWith(']')) {
913
- isModified = true;
918
+ privateStopNoop(...args) {
919
+ let e;
920
+ let fn;
921
+ if (args.length === 2) {
922
+ fn = args[0];
923
+ e = args[1];
924
+ }
925
+ else if (args.length === 1) {
926
+ e = args[0];
914
927
  }
915
- }
928
+ if (e.type === 'touchmove') {
929
+ report('catchtouchmove 转换后只能停止回调函数的冒泡,不能阻止滚动穿透。如要阻止滚动穿透,可以手动给编译后的 View 组件加上 catchMove 属性');
930
+ }
931
+ e.stopPropagation();
932
+ isFunction(fn) && fn(e);
916
933
  }
917
- if (isModified) {
918
- observers[observerKey].apply(this, keys.map(function (key) {
919
- return safeGet(current, key);
920
- }));
934
+ // ================ React 生命周期 ================
935
+ componentWillMount() {
936
+ this.safeExecute(super.componentWillMount);
937
+ this.executeLifeCycles(this.willMounts, this.current.router || {});
938
+ this.triggerObservers(this.data, BaseComponent.defaultProps);
939
+ this.triggerPropertiesObservers(BaseComponent.defaultProps, this.props);
921
940
  }
922
- }
923
- }
924
- }, {
925
- key: "defineProperty",
926
- value: function defineProperty(target, key, data) {
927
- Object.defineProperty(target, key, {
928
- configurable: true,
929
- enumerable: true,
930
- set: function set(value) {
931
- data[key] = value;
932
- },
933
- get: function get() {
934
- return data[key];
941
+ componentDidMount() {
942
+ this.safeExecute(super.componentDidMount);
943
+ this.executeLifeCycles(this.didMounts);
935
944
  }
936
- });
937
- }
938
- }, {
939
- key: "privateStopNoop",
940
- value: function privateStopNoop() {
941
- var e;
942
- var fn;
943
- if (arguments.length === 2) {
944
- fn = arguments.length <= 0 ? undefined : arguments[0];
945
- e = arguments.length <= 1 ? undefined : arguments[1];
946
- } else if (arguments.length === 1) {
947
- e = arguments.length <= 0 ? undefined : arguments[0];
948
- }
949
- if (e.type === 'touchmove') {
950
- report('catchtouchmove 转换后只能停止回调函数的冒泡,不能阻止滚动穿透。如要阻止滚动穿透,可以手动给编译后的 View 组件加上 catchMove 属性');
951
- }
952
- e.stopPropagation();
953
- isFunction(fn) && fn(e);
954
- }
955
- // ================ React 生命周期 ================
956
- }, {
957
- key: "componentWillMount",
958
- value: function componentWillMount() {
959
- this.safeExecute(_get__default["default"](_getPrototypeOf__default["default"](BaseComponent.prototype), "componentWillMount", this));
960
- this.executeLifeCycles(this.willMounts, this.current.router || {});
961
- this.triggerObservers(this.data, BaseComponent.defaultProps);
962
- this.triggerPropertiesObservers(BaseComponent.defaultProps, this.props);
963
- }
964
- }, {
965
- key: "componentDidMount",
966
- value: function componentDidMount() {
967
- this.safeExecute(_get__default["default"](_getPrototypeOf__default["default"](BaseComponent.prototype), "componentDidMount", this));
968
- this.executeLifeCycles(this.didMounts);
969
- }
970
- }, {
971
- key: "componentWillUnmount",
972
- value: function componentWillUnmount() {
973
- this.eventDestroyList.forEach(function (fn) {
974
- return fn();
975
- });
976
- this.safeExecute(_get__default["default"](_getPrototypeOf__default["default"](BaseComponent.prototype), "componentWillUnmount", this));
977
- this.executeLifeCycles(this.willUnmounts);
978
- }
979
- }, {
980
- key: "componentDidHide",
981
- value: function componentDidHide() {
982
- this.safeExecute(_get__default["default"](_getPrototypeOf__default["default"](BaseComponent.prototype), "componentDidHide", this));
983
- this.executeLifeCycles(this.didHides);
984
- }
985
- }, {
986
- key: "componentDidShow",
987
- value: function componentDidShow() {
988
- this.safeExecute(_get__default["default"](_getPrototypeOf__default["default"](BaseComponent.prototype), "componentDidShow", this), this.current.router || {});
989
- this.executeLifeCycles(this.didShows, this.current.router || {});
990
- }
991
- }, {
992
- key: "componentWillReceiveProps",
993
- value: function componentWillReceiveProps(nextProps) {
994
- this.triggerObservers(nextProps, this.props);
995
- this.triggerPropertiesObservers(this.props, nextProps);
996
- this.safeExecute(_get__default["default"](_getPrototypeOf__default["default"](BaseComponent.prototype), "componentWillReceiveProps", this));
997
- }
998
- // ================ 小程序 App, Page, Component 实例属性与方法 ================
999
- }, {
1000
- key: "is",
1001
- get: function get() {
1002
- return this.current.page.is;
1003
- }
1004
- }, {
1005
- key: "id",
1006
- get: function get() {
1007
- return this.current.page.id;
1008
- }
1009
- }, {
1010
- key: "dataset",
1011
- get: function get() {
1012
- return this.current.page.dataset;
1013
- }
1014
- }, {
1015
- key: "componentMethodsProxy",
1016
- value: function componentMethodsProxy(method) {
1017
- var _this5 = this;
1018
- return function () {
1019
- var page = _this5.current.page;
1020
- if (page === null || page === void 0 ? void 0 : page[method]) {
1021
- return page[method].apply(page, arguments);
1022
- } else if (method === 'createSelectorQuery') {
1023
- return taro.createSelectorQuery();
1024
- } else if (method === 'createIntersectionObserver') {
1025
- // @ts-ignore
1026
- return taro.createIntersectionObserver.apply(void 0, arguments);
1027
- } else if (method === 'createMediaQueryObserver') {
1028
- return taro.createMediaQueryObserver();
1029
- } else {
1030
- console.error("page \u4E0B\u6CA1\u6709 ".concat(method, " \u65B9\u6CD5"));
945
+ componentWillUnmount() {
946
+ this.eventDestroyList.forEach(fn => fn());
947
+ this.safeExecute(super.componentWillUnmount);
948
+ this.executeLifeCycles(this.willUnmounts);
949
+ }
950
+ componentDidHide() {
951
+ this.safeExecute(super.componentDidHide);
952
+ this.executeLifeCycles(this.didHides);
953
+ }
954
+ componentDidShow() {
955
+ this.safeExecute(super.componentDidShow, this.current.router || {});
956
+ this.executeLifeCycles(this.didShows, this.current.router || {});
957
+ }
958
+ componentWillReceiveProps(nextProps) {
959
+ this.triggerObservers(nextProps, this.props);
960
+ this.triggerPropertiesObservers(this.props, nextProps);
961
+ this.safeExecute(super.componentWillReceiveProps);
962
+ }
963
+ // ================ 小程序 App, Page, Component 实例属性与方法 ================
964
+ get is() {
965
+ return this.current.page.is;
966
+ }
967
+ get id() {
968
+ return this.current.page.id;
969
+ }
970
+ get dataset() {
971
+ return this.current.page.dataset;
972
+ }
973
+ componentMethodsProxy(method) {
974
+ return (...args) => {
975
+ const page = this.current.page;
976
+ if (page === null || page === void 0 ? void 0 : page[method]) {
977
+ return page[method](...args);
978
+ }
979
+ else if (method === 'createSelectorQuery') {
980
+ return taro.createSelectorQuery();
981
+ }
982
+ else if (method === 'createIntersectionObserver') {
983
+ // @ts-ignore
984
+ return taro.createIntersectionObserver(...args);
985
+ }
986
+ else if (method === 'createMediaQueryObserver') {
987
+ return taro.createMediaQueryObserver();
988
+ }
989
+ else {
990
+ console.error(`page 下没有 ${method} 方法`);
991
+ }
992
+ };
993
+ }
994
+ selectComponent() {
995
+ report(nonsupport.get('selectComponent'));
996
+ }
997
+ selectAllComponents() {
998
+ report(nonsupport.get('selectAllComponents'));
999
+ }
1000
+ selectOwnerComponent() {
1001
+ report(nonsupport.get('selectOwnerComponent'));
1002
+ }
1003
+ groupSetData() {
1004
+ report(nonsupport.get('groupSetData'));
1031
1005
  }
1032
- };
1033
- }
1034
- }, {
1035
- key: "selectComponent",
1036
- value: function selectComponent() {
1037
- report(nonsupport.get('selectComponent'));
1038
- }
1039
- }, {
1040
- key: "selectAllComponents",
1041
- value: function selectAllComponents() {
1042
- report(nonsupport.get('selectAllComponents'));
1043
- }
1044
- }, {
1045
- key: "selectOwnerComponent",
1046
- value: function selectOwnerComponent() {
1047
- report(nonsupport.get('selectOwnerComponent'));
1048
- }
1049
- }, {
1050
- key: "groupSetData",
1051
- value: function groupSetData() {
1052
- report(nonsupport.get('groupSetData'));
1053
1006
  }
1054
- }]);
1055
- return BaseComponent;
1056
- }(ConnectComponent);
1057
- var props = weappConf.properties;
1058
- if (props) {
1059
- for (var propKey in props) {
1060
- var propValue = props[propKey];
1061
- if (propValue != null && !isFunction(propValue)) {
1062
- if (propValue.value !== undefined) {
1063
- // 如果是 null 也赋值到 defaultProps
1064
- BaseComponent.defaultProps = Object.assign(_defineProperty__default["default"]({}, propKey, propValue.value), BaseComponent.defaultProps);
1065
- }
1007
+ const props = weappConf.properties;
1008
+ if (props) {
1009
+ for (const propKey in props) {
1010
+ const propValue = props[propKey];
1011
+ if (propValue != null && !isFunction(propValue)) {
1012
+ if (propValue.value !== undefined) { // 如果是 null 也赋值到 defaultProps
1013
+ BaseComponent.defaultProps = Object.assign({ [propKey]: propValue.value }, BaseComponent.defaultProps);
1014
+ }
1015
+ }
1016
+ }
1066
1017
  }
1067
- }
1068
- }
1069
- var staticOptions = ['externalClasses', 'relations', 'options'];
1070
- staticOptions.forEach(function (option) {
1071
- var value = weappConf[option];
1072
- if (value != null) {
1073
- BaseComponent[option] = value;
1074
- }
1075
- });
1076
- return BaseComponent;
1077
- };
1018
+ const staticOptions = ['externalClasses', 'relations', 'options'];
1019
+ staticOptions.forEach(option => {
1020
+ const value = weappConf[option];
1021
+ if (value != null) {
1022
+ BaseComponent[option] = value;
1023
+ }
1024
+ });
1025
+ return BaseComponent;
1026
+ };
1078
1027
  }
1079
1028
 
1080
1029
  exports.cacheOptions = cacheOptions;
1081
1030
  exports.convertToArray = convertToArray;
1082
- exports["default"] = withWeapp;
1031
+ exports.default = withWeapp;
1083
1032
  exports.getTarget = getTarget;
1084
1033
 
1085
1034
  Object.defineProperty(exports, '__esModule', { value: true });