@tarojs/with-weapp 3.6.5-alpha → 3.6.5-alpha.2

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