@tarojs/with-weapp 3.6.0-canary.0 → 3.6.0-canary.10

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.
package/dist/index.esm.js CHANGED
@@ -16,25 +16,19 @@ var json = JSON;
16
16
  var clone = function clone(obj) {
17
17
  return json.parse(stringify(obj));
18
18
  };
19
-
20
19
  var isArray = Array.isArray || function (x) {
21
20
  return {}.toString.call(x) === '[object Array]';
22
21
  };
23
-
24
22
  var objectKeys = Object.keys || function (obj) {
25
23
  var has = Object.prototype.hasOwnProperty || function () {
26
24
  return true;
27
25
  };
28
-
29
26
  var keys = [];
30
-
31
27
  for (var key in obj) {
32
28
  if (has.call(obj, key)) keys.push(key);
33
29
  }
34
-
35
30
  return keys;
36
31
  };
37
-
38
32
  function stringify(obj, opts) {
39
33
  if (!opts) opts = {};
40
34
  if (typeof opts === 'function') opts = {
@@ -43,11 +37,9 @@ function stringify(obj, opts) {
43
37
  var space = opts.space || '';
44
38
  if (typeof space === 'number') space = Array(space + 1).join(' ');
45
39
  var cycles = typeof opts.cycles === 'boolean' ? opts.cycles : false;
46
-
47
40
  var replacer = opts.replacer || function (key, value) {
48
41
  return value;
49
42
  };
50
-
51
43
  var cmp = opts.cmp && function (f) {
52
44
  return function (node) {
53
45
  return function (a, b) {
@@ -63,53 +55,41 @@ function stringify(obj, opts) {
63
55
  };
64
56
  };
65
57
  }(opts.cmp);
66
-
67
58
  var seen = [];
68
59
  return function stringify(parent, key, node, level) {
69
60
  var indent = space ? '\n' + new Array(level + 1).join(space) : '';
70
61
  var colonSeparator = space ? ': ' : ':';
71
-
72
62
  if (node && node.toJSON && typeof node.toJSON === 'function') {
73
63
  node = node.toJSON();
74
64
  }
75
-
76
65
  node = replacer.call(parent, key, node);
77
-
78
66
  if (node === undefined) {
79
67
  return;
80
68
  }
81
-
82
69
  if (_typeof(node) !== 'object' || node === null) {
83
70
  return json.stringify(node);
84
71
  }
85
-
86
72
  if (isArray(node)) {
87
73
  var out = [];
88
-
89
74
  for (var i = 0; i < node.length; i++) {
90
75
  var item = stringify(node, i, node[i], level + 1) || json.stringify(null);
91
76
  out.push(indent + space + item);
92
77
  }
93
-
94
78
  return '[' + out.join(',') + indent + ']';
95
79
  } else {
96
80
  if (seen.indexOf(node) !== -1) {
97
81
  if (cycles) return json.stringify('__cycle__');
98
82
  throw new TypeError('Converting circular structure to JSON');
99
83
  } else seen.push(node);
100
-
101
84
  var keys = objectKeys(node).sort(cmp && cmp(node));
102
85
  var _out = [];
103
-
104
86
  for (var _i = 0; _i < keys.length; _i++) {
105
87
  var _key = keys[_i];
106
88
  var value = stringify(node, _key, node[_key], level + 1);
107
89
  if (!value) continue;
108
90
  var keyValue = json.stringify(_key) + colonSeparator + value;
109
-
110
91
  _out.push(indent + space + keyValue);
111
92
  }
112
-
113
93
  seen.splice(seen.indexOf(node), 1);
114
94
  return '{' + _out.join(',') + indent + '}';
115
95
  }
@@ -125,29 +105,24 @@ var FUNCTIONTYPE = '[object Function]';
125
105
  function diff(current, pre) {
126
106
  var result = {};
127
107
  syncKeys(current, pre);
128
-
129
108
  _diff(current, pre, '', result);
130
-
131
109
  return result;
132
110
  }
133
-
134
111
  function syncKeys(current, pre) {
135
112
  if (current === pre) return;
136
113
  var rootCurrentType = type(current);
137
114
  var rootPreType = type(pre);
138
-
139
115
  if (rootCurrentType == OBJECTTYPE && rootPreType == OBJECTTYPE) {
140
116
  // if(Object.keys(current).length >= Object.keys(pre).length){
141
117
  for (var key in pre) {
142
118
  var currentValue = current[key];
143
-
144
119
  if (currentValue === undefined) {
145
120
  current[key] = null;
146
121
  } else {
147
122
  syncKeys(currentValue, pre[key]);
148
123
  }
149
- } // }
150
-
124
+ }
125
+ // }
151
126
  } else if (rootCurrentType == ARRAYTYPE && rootPreType == ARRAYTYPE) {
152
127
  if (current.length >= pre.length) {
153
128
  pre.forEach(function (item, index) {
@@ -156,12 +131,10 @@ function syncKeys(current, pre) {
156
131
  }
157
132
  }
158
133
  }
159
-
160
134
  function _diff(current, pre, path, result) {
161
135
  if (current === pre) return;
162
136
  var rootCurrentType = type(current);
163
137
  var rootPreType = type(pre);
164
-
165
138
  if (rootCurrentType == OBJECTTYPE) {
166
139
  if (rootPreType != OBJECTTYPE || Object.keys(current).length < Object.keys(pre).length) {
167
140
  setResult(result, path, current);
@@ -171,7 +144,6 @@ function _diff(current, pre, path, result) {
171
144
  var preValue = pre[key];
172
145
  var currentType = type(currentValue);
173
146
  var preType = type(preValue);
174
-
175
147
  if (currentType != ARRAYTYPE && currentType != OBJECTTYPE) {
176
148
  if (currentValue != pre[key]) {
177
149
  setResult(result, (path == '' ? '' : path + '.') + key, currentValue);
@@ -198,7 +170,6 @@ function _diff(current, pre, path, result) {
198
170
  }
199
171
  }
200
172
  };
201
-
202
173
  for (var key in current) {
203
174
  _loop(key);
204
175
  }
@@ -219,21 +190,17 @@ function _diff(current, pre, path, result) {
219
190
  setResult(result, path, current);
220
191
  }
221
192
  }
222
-
223
193
  function setResult(result, k, v) {
224
194
  if (type(v) != FUNCTIONTYPE) {
225
195
  result[k] = v;
226
196
  }
227
197
  }
228
-
229
198
  function type(obj) {
230
199
  return Object.prototype.toString.call(obj);
231
200
  }
232
201
 
233
202
  var _lifecycleMap;
234
-
235
203
  var TaroLifeCycles;
236
-
237
204
  (function (TaroLifeCycles) {
238
205
  TaroLifeCycles["WillMount"] = "componentWillMount";
239
206
  TaroLifeCycles["DidMount"] = "componentDidMount";
@@ -241,38 +208,27 @@ var TaroLifeCycles;
241
208
  TaroLifeCycles["DidHide"] = "componentDidHide";
242
209
  TaroLifeCycles["WillUnmount"] = "componentWillUnmount";
243
210
  })(TaroLifeCycles || (TaroLifeCycles = {}));
244
-
245
211
  var lifecycleMap = (_lifecycleMap = {}, _defineProperty(_lifecycleMap, TaroLifeCycles.WillMount, ['created']), _defineProperty(_lifecycleMap, TaroLifeCycles.DidMount, ['attached']), _defineProperty(_lifecycleMap, TaroLifeCycles.DidShow, ['onShow']), _defineProperty(_lifecycleMap, TaroLifeCycles.DidHide, ['onHide']), _defineProperty(_lifecycleMap, TaroLifeCycles.WillUnmount, ['detached', 'onUnload']), _lifecycleMap);
246
212
  var lifecycles = new Set(['ready']);
247
-
248
213
  for (var key in lifecycleMap) {
249
214
  var lifecycle = lifecycleMap[key];
250
215
  lifecycle.forEach(function (l) {
251
216
  return lifecycles.add(l);
252
217
  });
253
218
  }
254
-
255
219
  var uniquePageLifecycle = ['onPullDownRefresh', 'onReachBottom', 'onShareAppMessage', 'onShareTimeline', 'onAddToFavorites', 'onPageScroll', 'onResize', 'onTabItemTap'];
256
220
  var appOptions = ['onLaunch', 'onShow', 'onHide', 'onError', 'onPageNotFound', 'onUnhandledRejection', 'onThemeChange'];
257
221
 
258
222
  /**
259
223
  * Simple bind, faster than native
260
224
  */
261
- function bind(fn
262
- /*: Function */
263
- , ctx
264
- /*: Object */
265
- ) {
225
+ function bind(fn /*: Function */, ctx /*: Object */) {
266
226
  if (!fn) return false;
267
-
268
227
  function boundFn(a) {
269
- var l
270
- /*: number */
271
- = arguments.length;
228
+ var l /*: number */ = arguments.length;
272
229
  return l ? l > 1 ? fn.apply(ctx, arguments) : fn.call(ctx, a) : fn.call(ctx);
273
- } // record original fn length
274
-
275
-
230
+ }
231
+ // record original fn length
276
232
  boundFn._length = fn.length;
277
233
  return boundFn;
278
234
  }
@@ -283,40 +239,30 @@ function safeGet(obj, propsArg, defaultValue) {
283
239
  if (!obj) {
284
240
  return defaultValue;
285
241
  }
286
-
287
242
  var props, prop;
288
-
289
243
  if (Array.isArray(propsArg)) {
290
244
  props = propsArg.slice(0);
291
245
  }
292
-
293
246
  if (typeof propsArg === 'string') {
294
247
  props = propsArg.replace(/\[(.+?)\]/g, '.$1');
295
248
  props = props.split('.');
296
249
  }
297
-
298
250
  if (_typeof(propsArg) === 'symbol') {
299
251
  props = [propsArg];
300
252
  }
301
-
302
253
  if (!Array.isArray(props)) {
303
254
  throw new Error('props arg must be an array, a string or a symbol');
304
255
  }
305
-
306
256
  while (props.length) {
307
257
  prop = props.shift();
308
-
309
258
  if (!obj) {
310
259
  return defaultValue;
311
260
  }
312
-
313
261
  obj = obj[prop];
314
-
315
262
  if (obj === undefined) {
316
263
  return defaultValue;
317
264
  }
318
265
  }
319
-
320
266
  return obj;
321
267
  }
322
268
  function safeSet(obj, props, value) {
@@ -324,39 +270,30 @@ function safeSet(obj, props, value) {
324
270
  props = props.replace(/\[(.+?)\]/g, '.$1');
325
271
  props = props.split('.');
326
272
  }
327
-
328
273
  if (_typeof(props) === 'symbol') {
329
274
  props = [props];
330
275
  }
331
-
332
276
  var lastProp = props.pop();
333
-
334
277
  if (!lastProp) {
335
278
  return false;
336
279
  }
337
-
338
280
  var thisProp;
339
-
340
281
  while (thisProp = props.shift()) {
341
282
  if (typeof obj[thisProp] === 'undefined') {
342
283
  obj[thisProp] = {};
343
- } // 直接按路径修改 this.state 可能会导致 nextProps 也被修改
284
+ }
285
+ // 直接按路径修改 this.state 可能会导致 nextProps 也被修改
344
286
  // 因此按路径寻找时,每一层都复制一遍
345
-
346
-
347
287
  if (Array.isArray(obj[thisProp])) {
348
288
  obj[thisProp] = _toConsumableArray(obj[thisProp]);
349
289
  } else if (_typeof(obj[thisProp]) === 'object') {
350
290
  obj[thisProp] = Object.assign({}, obj[thisProp]);
351
291
  }
352
-
353
292
  obj = obj[thisProp];
354
-
355
293
  if (!obj || _typeof(obj) !== 'object') {
356
294
  return false;
357
295
  }
358
296
  }
359
-
360
297
  obj[lastProp] = value;
361
298
  return true;
362
299
  }
@@ -368,22 +305,18 @@ function flattenBehaviors(behavior, behaviorMap) {
368
305
  if (typeof behavior === 'string') {
369
306
  return report("\u4E0D\u652F\u6301\u4F7F\u7528\u5185\u7F6E Behavior: [".concat(behavior, "]"));
370
307
  }
371
-
372
308
  var subBehaviors = behavior.behaviors;
373
-
374
309
  if (subBehaviors === null || subBehaviors === void 0 ? void 0 : subBehaviors.length) {
375
310
  subBehaviors.forEach(function (subBehavior) {
376
311
  return flattenBehaviors(subBehavior, behaviorMap);
377
312
  });
378
313
  }
379
-
380
314
  Object.keys(behavior).forEach(function (key) {
381
315
  // 不支持的属性
382
316
  if (nonsupport.has(key)) {
383
317
  var advise = nonsupport.get(key);
384
318
  return report(advise);
385
319
  }
386
-
387
320
  if (behaviorMap.has(key)) {
388
321
  var list = behaviorMap.get(key);
389
322
  var value = behavior[key];
@@ -393,15 +326,10 @@ function flattenBehaviors(behavior, behaviorMap) {
393
326
  }
394
327
 
395
328
  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; } } }; }
396
-
397
329
  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); }
398
-
399
330
  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; }
400
-
401
331
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
402
-
403
332
  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; } }
404
-
405
333
  function defineGetter(component, key, getter) {
406
334
  Object.defineProperty(component, key, {
407
335
  enumerable: true,
@@ -410,71 +338,55 @@ function defineGetter(component, key, getter) {
410
338
  if (getter === 'props') {
411
339
  return component.props;
412
340
  }
413
-
414
341
  return Object.assign(Object.assign({}, component.state), component.props);
415
342
  }
416
343
  });
417
344
  }
418
-
419
345
  function isFunction(o) {
420
346
  return typeof o === 'function';
421
347
  }
422
-
423
348
  function withWeapp(weappConf) {
424
349
  var isApp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
425
-
426
350
  if (_typeof(weappConf) === 'object' && Object.keys(weappConf).length === 0) {
427
351
  report('withWeapp 请传入“App/页面/组件“的配置对象。如果原生写法使用了基类,请将基类组合后的配置对象传入,详情请参考文档。');
428
352
  }
429
-
430
353
  return function (ConnectComponent) {
431
354
  var _a;
432
-
433
355
  var behaviorMap = new Map([['properties', []], ['data', []], ['methods', []], ['created', []], ['attached', []], ['ready', []], ['detached', []]]);
434
356
  var behaviorProperties = {};
435
-
436
357
  if ((_a = weappConf.behaviors) === null || _a === void 0 ? void 0 : _a.length) {
437
358
  var behaviors = weappConf.behaviors;
438
359
  behaviors.forEach(function (behavior) {
439
360
  return flattenBehaviors(behavior, behaviorMap);
440
361
  });
441
362
  var propertiesList = behaviorMap.get('properties');
442
-
443
363
  if (propertiesList.length) {
444
364
  propertiesList.forEach(function (property) {
445
365
  Object.assign(behaviorProperties, property);
446
366
  });
447
367
  Object.keys(behaviorProperties).forEach(function (propName) {
448
368
  var propValue = behaviorProperties[propName];
449
-
450
369
  if (!weappConf.properties) {
451
370
  weappConf.properties = {};
452
371
  }
453
-
454
372
  if (!weappConf.properties.hasOwnProperty(propName)) {
455
373
  if (propValue && _typeof(propValue) === 'object' && propValue.value) {
456
374
  propValue.value = clone(propValue.value);
457
375
  }
458
-
459
376
  weappConf.properties[propName] = propValue;
460
377
  }
461
378
  });
462
379
  }
463
380
  }
464
-
465
381
  var BaseComponent = /*#__PURE__*/function (_ConnectComponent) {
466
382
  _inherits(BaseComponent, _ConnectComponent);
467
-
468
383
  var _super = _createSuper(BaseComponent);
469
-
470
384
  function BaseComponent(props) {
471
385
  var _this;
472
-
473
386
  _classCallCheck(this, BaseComponent);
474
-
475
387
  _this = _super.call(this, props);
476
- _this._observeProps = []; // mixins 可以多次调用生命周期
477
-
388
+ _this._observeProps = [];
389
+ // mixins 可以多次调用生命周期
478
390
  _this.willMounts = [];
479
391
  _this.didMounts = [];
480
392
  _this.didHides = [];
@@ -483,57 +395,44 @@ function withWeapp(weappConf) {
483
395
  _this.eventDestroyList = [];
484
396
  _this.current = getCurrentInstance();
485
397
  _this.taroGlobalData = Object.create(null);
486
-
487
398
  _this.safeExecute = function (func) {
488
399
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
489
400
  args[_key - 1] = arguments[_key];
490
401
  }
491
-
492
402
  if (isFunction(func)) func.apply(_assertThisInitialized(_this), args);
493
403
  };
494
-
495
404
  _this.setData = function (obj, callback) {
496
405
  var oldState;
497
-
498
406
  if (_this.observers && Object.keys(Object.keys(_this.observers))) {
499
407
  oldState = clone(_this.state);
500
408
  }
501
-
502
409
  Object.keys(obj).forEach(function (key) {
503
410
  safeSet(_this.state, key, obj[key]);
504
411
  });
505
-
506
412
  _this.setState(_this.state, function () {
507
413
  _this.triggerObservers(_this.state, oldState);
508
-
509
414
  if (callback) {
510
415
  callback.call(_assertThisInitialized(_this));
511
416
  }
512
417
  });
513
418
  };
514
-
515
419
  _this.triggerEvent = function (eventName, detail, options) {
516
420
  if (options) {
517
421
  report('triggerEvent 不支持事件选项。');
518
- } // eventName support kebab case
519
-
520
-
422
+ }
423
+ // eventName support kebab case
521
424
  if (eventName.match(/[a-z]+-[a-z]+/g)) {
522
425
  eventName = eventName.replace(/-[a-z]/g, function (match) {
523
426
  return match[1].toUpperCase();
524
427
  });
525
428
  }
526
-
527
429
  var props = _this.props;
528
430
  var dataset = {};
529
-
530
431
  for (var key in props) {
531
432
  if (!key.startsWith('data-')) continue;
532
433
  dataset[key.replace(/^data-/, '')] = props[key];
533
434
  }
534
-
535
435
  var func = props["on".concat(eventName[0].toUpperCase()).concat(eventName.slice(1))];
536
-
537
436
  if (isFunction(func)) {
538
437
  func.call(_assertThisInitialized(_this), {
539
438
  type: eventName,
@@ -549,7 +448,6 @@ function withWeapp(weappConf) {
549
448
  });
550
449
  }
551
450
  };
552
-
553
451
  _this.hasBehavior = _this.componentMethodsProxy('hasBehavior');
554
452
  _this.createSelectorQuery = _this.componentMethodsProxy('createSelectorQuery');
555
453
  _this.createIntersectionObserver = _this.componentMethodsProxy('createIntersectionObserver');
@@ -561,21 +459,18 @@ function withWeapp(weappConf) {
561
459
  _this.clearAnimation = _this.componentMethodsProxy('clearAnimation');
562
460
  _this.setUpdatePerformanceListener = _this.componentMethodsProxy('setUpdatePerformanceListener');
563
461
  _this.state = _this.state || {};
564
-
565
462
  _this.init(weappConf);
566
-
567
463
  defineGetter(_assertThisInitialized(_this), 'data', 'state');
568
464
  defineGetter(_assertThisInitialized(_this), 'properties', 'props');
569
465
  return _this;
570
466
  }
571
-
572
467
  _createClass(BaseComponent, [{
573
468
  key: "initProps",
574
469
  value: function initProps(props) {
575
470
  for (var propKey in props) {
576
471
  if (props.hasOwnProperty(propKey)) {
577
- var propValue = props[propKey]; // propValue 可能是 null, 构造函数, 对象
578
-
472
+ var propValue = props[propKey];
473
+ // propValue 可能是 null, 构造函数, 对象
579
474
  if (propValue && !isFunction(propValue)) {
580
475
  if (propValue.observer) {
581
476
  this._observeProps.push({
@@ -591,20 +486,16 @@ function withWeapp(weappConf) {
591
486
  key: "init",
592
487
  value: function init(options) {
593
488
  var _this2 = this;
594
-
595
- var _a, _b, _c; // 处理 Behaviors
596
-
597
-
489
+ var _a, _b, _c;
490
+ // 处理 Behaviors
598
491
  if ((_a = options.behaviors) === null || _a === void 0 ? void 0 : _a.length) {
599
492
  var _iterator = _createForOfIteratorHelper(behaviorMap.entries()),
600
- _step;
601
-
493
+ _step;
602
494
  try {
603
495
  var _loop = function _loop() {
604
496
  var _step$value = _slicedToArray(_step.value, 2),
605
- key = _step$value[0],
606
- list = _step$value[1];
607
-
497
+ key = _step$value[0],
498
+ list = _step$value[1];
608
499
  switch (key) {
609
500
  case 'created':
610
501
  case 'attached':
@@ -616,7 +507,6 @@ function withWeapp(weappConf) {
616
507
  break;
617
508
  }
618
509
  };
619
-
620
510
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
621
511
  _loop();
622
512
  }
@@ -626,71 +516,56 @@ function withWeapp(weappConf) {
626
516
  _iterator.f();
627
517
  }
628
518
  }
629
-
630
519
  for (var confKey in options) {
631
520
  // 不支持的属性
632
521
  if (nonsupport.has(confKey)) {
633
522
  var advise = nonsupport.get(confKey);
634
523
  report(advise);
635
524
  }
636
-
637
525
  var confValue = options[confKey];
638
-
639
526
  switch (confKey) {
640
527
  case 'behaviors':
641
528
  break;
642
-
643
529
  case 'data':
644
530
  {
645
531
  if (isApp) {
646
532
  this[confKey] = confValue;
647
-
648
533
  if (!appOptions.includes(confKey)) {
649
534
  this.defineProperty(this.taroGlobalData, confKey, this);
650
535
  }
651
536
  } else {
652
537
  this.state = Object.assign(Object.assign({}, confValue), this.state);
653
538
  }
654
-
655
539
  break;
656
540
  }
657
-
658
541
  case 'properties':
659
542
  this.initProps(Object.assign(behaviorProperties, confValue));
660
543
  break;
661
-
662
544
  case 'methods':
663
545
  for (var key in confValue) {
664
546
  var method = confValue[key];
665
547
  this[key] = bind(method, this);
666
548
  }
667
-
668
549
  break;
669
-
670
550
  case 'lifetimes':
671
551
  for (var _key2 in confValue) {
672
552
  this.initLifeCycles(_key2, confValue[_key2]);
673
553
  }
674
-
675
554
  break;
676
-
677
555
  case 'pageLifetimes':
678
556
  for (var _key3 in confValue) {
679
557
  var cb = confValue[_key3];
680
-
681
558
  switch (_key3) {
682
559
  case 'show':
683
560
  {
684
561
  this.initLifeCycleListener('show', cb);
685
562
  break;
686
563
  }
687
-
688
564
  case 'hide':
689
565
  {
690
566
  this.initLifeCycleListener('hide', cb);
691
567
  break;
692
568
  }
693
-
694
569
  case 'resize':
695
570
  {
696
571
  report('不支持组件所在页面的生命周期 pageLifetimes.resize。');
@@ -698,67 +573,53 @@ function withWeapp(weappConf) {
698
573
  }
699
574
  }
700
575
  }
701
-
702
576
  break;
703
-
704
577
  default:
705
578
  if (lifecycles.has(confKey)) {
706
579
  // 优先使用 lifetimes 中定义的生命周期
707
580
  if ((_b = options.lifetimes) === null || _b === void 0 ? void 0 : _b[confKey]) {
708
581
  break;
709
582
  }
710
-
711
583
  var lifecycle = options[confKey];
712
584
  this.initLifeCycles(confKey, lifecycle);
713
585
  } else if (isFunction(confValue)) {
714
586
  this[confKey] = bind(confValue, this);
715
-
716
587
  if (isApp && !appOptions.includes(confKey)) {
717
588
  this.defineProperty(this.taroGlobalData, confKey, this);
718
- } // 原生页面和 Taro 页面中共计只能定义一次的生命周期
719
-
720
-
589
+ }
590
+ // 原生页面和 Taro 页面中共计只能定义一次的生命周期
721
591
  if (uniquePageLifecycle.includes(confKey) && ConnectComponent.prototype[confKey]) {
722
592
  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"));
723
593
  }
724
594
  } else {
725
595
  this[confKey] = confValue;
726
-
727
596
  if (isApp && !appOptions.includes(confKey)) {
728
597
  this.defineProperty(this.taroGlobalData, confKey, this);
729
598
  }
730
599
  }
731
-
732
600
  break;
733
601
  }
734
- } // 处理 Behaviors
735
-
736
-
602
+ }
603
+ // 处理 Behaviors
737
604
  if ((_c = options.behaviors) === null || _c === void 0 ? void 0 : _c.length) {
738
605
  (function () {
739
606
  var behaviorData = {};
740
607
  var methods = {};
741
-
742
608
  var _iterator2 = _createForOfIteratorHelper(behaviorMap.entries()),
743
- _step2;
744
-
609
+ _step2;
745
610
  try {
746
611
  var _loop2 = function _loop2() {
747
612
  var _step2$value = _slicedToArray(_step2.value, 2),
748
- key = _step2$value[0],
749
- list = _step2$value[1];
750
-
613
+ key = _step2$value[0],
614
+ list = _step2$value[1];
751
615
  switch (key) {
752
616
  case 'data':
753
617
  [].concat(_toConsumableArray(list), [_this2.state]).forEach(function (dataObject, index) {
754
618
  Object.keys(dataObject).forEach(function (dataKey) {
755
619
  var value = dataObject[dataKey];
756
620
  var preValue = behaviorData[dataKey];
757
-
758
621
  var valueType = _typeof(value);
759
-
760
622
  var preValueType = _typeof(preValue);
761
-
762
623
  if (valueType === 'object') {
763
624
  if (!value) {
764
625
  behaviorData[dataKey] = value;
@@ -775,7 +636,6 @@ function withWeapp(weappConf) {
775
636
  });
776
637
  _this2.state = behaviorData;
777
638
  break;
778
-
779
639
  case 'methods':
780
640
  list.forEach(function (methodsObject) {
781
641
  Object.assign(methods, methodsObject);
@@ -787,12 +647,10 @@ function withWeapp(weappConf) {
787
647
  }
788
648
  });
789
649
  break;
790
-
791
650
  default:
792
651
  break;
793
652
  }
794
653
  };
795
-
796
654
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
797
655
  _loop2();
798
656
  }
@@ -812,17 +670,14 @@ function withWeapp(weappConf) {
812
670
  var advise = nonsupport.get(lifecycleName);
813
671
  return report(advise);
814
672
  }
815
-
816
673
  if (lifecycleName === 'ready') {
817
674
  // 如果组件是延时渲染的,页面 onReady 的事件已经 emit 了,因此使用 componentDidMount + nextTick 模拟
818
675
  if (this.current.page.onReady.called) {
819
676
  this.didMounts.push(function () {
820
677
  var _this3 = this;
821
-
822
678
  for (var _len2 = arguments.length, args = new Array(_len2), _key4 = 0; _key4 < _len2; _key4++) {
823
679
  args[_key4] = arguments[_key4];
824
680
  }
825
-
826
681
  nextTick(function () {
827
682
  if (isFunction(lifecycle)) {
828
683
  lifecycle.apply(_this3, args);
@@ -835,34 +690,28 @@ function withWeapp(weappConf) {
835
690
  } else {
836
691
  for (var lifecycleKey in lifecycleMap) {
837
692
  var cycleNames = lifecycleMap[lifecycleKey];
838
-
839
693
  if (cycleNames.indexOf(lifecycleName) !== -1) {
840
694
  switch (lifecycleKey) {
841
695
  case TaroLifeCycles.DidHide:
842
696
  this.didHides.push(lifecycle);
843
697
  break;
844
-
845
698
  case TaroLifeCycles.DidMount:
846
699
  this.didMounts.push(lifecycle);
847
700
  break;
848
-
849
701
  case TaroLifeCycles.DidShow:
850
702
  this.didShows.push(lifecycle);
851
703
  break;
852
-
853
704
  case TaroLifeCycles.WillMount:
854
705
  this.willMounts.push(lifecycle);
855
706
  break;
856
-
857
707
  case TaroLifeCycles.WillUnmount:
858
708
  this.willUnmounts.push(lifecycle);
859
709
  break;
860
710
  }
861
711
  }
862
712
  }
863
- } // mixins 不会覆盖已经设置的生命周期,加入到 this 是为了形如 this.created() 的调用
864
-
865
-
713
+ }
714
+ // mixins 不会覆盖已经设置的生命周期,加入到 this 是为了形如 this.created() 的调用
866
715
  if (!isFunction(this[lifecycleName])) {
867
716
  this[lifecycleName] = lifecycle;
868
717
  }
@@ -874,8 +723,8 @@ function withWeapp(weappConf) {
874
723
  var router = this.current.router;
875
724
  var lifecycleName = "on".concat(name[0].toUpperCase()).concat(name.slice(1));
876
725
  cb = cb.bind(this);
877
- (router === null || router === void 0 ? void 0 : router[lifecycleName]) && eventCenter.on(router[lifecycleName], cb); // unMount 时需要取消事件监听
878
-
726
+ (router === null || router === void 0 ? void 0 : router[lifecycleName]) && eventCenter.on(router[lifecycleName], cb);
727
+ // unMount 时需要取消事件监听
879
728
  this.eventDestroyList.push(function () {
880
729
  return eventCenter.off(router[lifecycleName], cb);
881
730
  });
@@ -886,7 +735,6 @@ function withWeapp(weappConf) {
886
735
  for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key5 = 1; _key5 < _len3; _key5++) {
887
736
  args[_key5 - 1] = arguments[_key5];
888
737
  }
889
-
890
738
  for (var i = 0; i < funcs.length; i++) {
891
739
  var func = funcs[i];
892
740
  this.safeExecute.apply(this, [func].concat(args));
@@ -896,17 +744,15 @@ function withWeapp(weappConf) {
896
744
  key: "triggerPropertiesObservers",
897
745
  value: function triggerPropertiesObservers(prevProps, nextProps) {
898
746
  var _this4 = this;
899
-
900
747
  this._observeProps.forEach(function (_ref) {
901
748
  var key = _ref.name,
902
- observer = _ref.observer;
749
+ observer = _ref.observer;
903
750
  var prop = prevProps === null || prevProps === void 0 ? void 0 : prevProps[key];
904
- var nextProp = nextProps[key]; // 小程序是深比较不同之后才 trigger observer
905
-
751
+ var nextProp = nextProps[key];
752
+ // 小程序是深比较不同之后才 trigger observer
906
753
  if (!isEqual(prop, nextProp)) {
907
754
  if (typeof observer === 'string') {
908
755
  var ob = _this4[observer];
909
-
910
756
  if (isFunction(ob)) {
911
757
  ob.call(_this4, nextProp, prop, key);
912
758
  }
@@ -920,45 +766,35 @@ function withWeapp(weappConf) {
920
766
  key: "triggerObservers",
921
767
  value: function triggerObservers(current, prev) {
922
768
  var observers = this.observers;
923
-
924
769
  if (observers == null) {
925
770
  return;
926
771
  }
927
-
928
772
  if (Object.keys(observers).length === 0) {
929
773
  return;
930
774
  }
931
-
932
775
  var result = diff(current, prev);
933
776
  var resultKeys = Object.keys(result);
934
-
935
777
  if (resultKeys.length === 0) {
936
778
  return;
937
779
  }
938
-
939
780
  for (var observerKey in observers) {
940
781
  if (/\*\*/.test(observerKey)) {
941
782
  report('数据监听器 observers 不支持使用通配符 **。');
942
783
  continue;
943
784
  }
944
-
945
785
  var keys = observerKey.split(',').map(function (k) {
946
786
  return k.trim();
947
787
  });
948
788
  var isModified = false;
949
-
950
789
  for (var i = 0; i < keys.length; i++) {
951
790
  var key = keys[i];
952
-
953
791
  for (var j = 0; j < resultKeys.length; j++) {
954
792
  var resultKey = resultKeys[j];
955
-
956
793
  if (resultKey.startsWith(key) || key.startsWith(resultKey) && key.endsWith(']')) {
957
794
  isModified = true;
958
795
  }
959
796
  }
960
797
  }
961
-
962
798
  if (isModified) {
963
799
  observers[observerKey].apply(this, keys.map(function (key) {
964
800
  return safeGet(current, key);
@@ -985,22 +821,19 @@ function withWeapp(weappConf) {
985
821
  value: function privateStopNoop() {
986
822
  var e;
987
823
  var fn;
988
-
989
824
  if (arguments.length === 2) {
990
825
  fn = arguments.length <= 0 ? undefined : arguments[0];
991
826
  e = arguments.length <= 1 ? undefined : arguments[1];
992
827
  } else if (arguments.length === 1) {
993
828
  e = arguments.length <= 0 ? undefined : arguments[0];
994
829
  }
995
-
996
830
  if (e.type === 'touchmove') {
997
831
  report('catchtouchmove 转换后只能停止回调函数的冒泡,不能阻止滚动穿透。如要阻止滚动穿透,可以手动给编译后的 View 组件加上 catchMove 属性');
998
832
  }
999
-
1000
833
  e.stopPropagation();
1001
834
  isFunction(fn) && fn(e);
1002
- } // ================ React 生命周期 ================
1003
-
835
+ }
836
+ // ================ React 生命周期 ================
1004
837
  }, {
1005
838
  key: "componentWillMount",
1006
839
  value: function componentWillMount() {
@@ -1042,8 +875,8 @@ function withWeapp(weappConf) {
1042
875
  this.triggerObservers(nextProps, this.props);
1043
876
  this.triggerPropertiesObservers(this.props, nextProps);
1044
877
  this.safeExecute(_get(_getPrototypeOf(BaseComponent.prototype), "componentWillReceiveProps", this));
1045
- } // ================ 小程序 App, Page, Component 实例属性与方法 ================
1046
-
878
+ }
879
+ // ================ 小程序 App, Page, Component 实例属性与方法 ================
1047
880
  }, {
1048
881
  key: "is",
1049
882
  get: function get() {
@@ -1063,10 +896,8 @@ function withWeapp(weappConf) {
1063
896
  key: "componentMethodsProxy",
1064
897
  value: function componentMethodsProxy(method) {
1065
898
  var _this5 = this;
1066
-
1067
899
  return function () {
1068
900
  var page = _this5.current.page;
1069
-
1070
901
  if (page === null || page === void 0 ? void 0 : page[method]) {
1071
902
  return page[method].apply(page, arguments);
1072
903
  } else {
@@ -1095,16 +926,12 @@ function withWeapp(weappConf) {
1095
926
  report(nonsupport.get('groupSetData'));
1096
927
  }
1097
928
  }]);
1098
-
1099
929
  return BaseComponent;
1100
930
  }(ConnectComponent);
1101
-
1102
931
  var props = weappConf.properties;
1103
-
1104
932
  if (props) {
1105
933
  for (var propKey in props) {
1106
934
  var propValue = props[propKey];
1107
-
1108
935
  if (propValue != null && !isFunction(propValue)) {
1109
936
  if (propValue.value !== undefined) {
1110
937
  // 如果是 null 也赋值到 defaultProps
@@ -1113,11 +940,9 @@ function withWeapp(weappConf) {
1113
940
  }
1114
941
  }
1115
942
  }
1116
-
1117
943
  var staticOptions = ['externalClasses', 'relations', 'options'];
1118
944
  staticOptions.forEach(function (option) {
1119
945
  var value = weappConf[option];
1120
-
1121
946
  if (value != null) {
1122
947
  BaseComponent[option] = value;
1123
948
  }