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