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