@tarojs/with-weapp 3.5.11 → 3.6.0-alpha.1

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