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