@tarojs/with-weapp 3.6.0-canary.8 → 3.6.0

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