@tarojs/with-weapp 4.0.0-beta.1 → 4.0.0-beta.10
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/LICENSE +14 -0
- package/dist/index.esm.js +529 -651
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +529 -665
- package/dist/index.js.map +1 -1
- package/dist/with-weapp.js +533 -658
- package/dist/with-weapp.js.map +1 -1
- package/package.json +4 -3
- package/src/convert-tools.ts +3 -3
- package/src/index.ts +4 -2
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
|
}
|
|
@@ -213,16 +194,20 @@
|
|
|
213
194
|
TaroLifeCycles["DidHide"] = "componentDidHide";
|
|
214
195
|
TaroLifeCycles["WillUnmount"] = "componentWillUnmount";
|
|
215
196
|
})(TaroLifeCycles || (TaroLifeCycles = {}));
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
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));
|
|
223
208
|
}
|
|
224
|
-
|
|
225
|
-
|
|
209
|
+
const uniquePageLifecycle = ['onPullDownRefresh', 'onReachBottom', 'onShareAppMessage', 'onShareTimeline', 'onAddToFavorites', 'onPageScroll', 'onResize', 'onTabItemTap'];
|
|
210
|
+
const appOptions = ['onLaunch', 'onShow', 'onHide', 'onError', 'onPageNotFound', 'onUnhandledRejection', 'onThemeChange'];
|
|
226
211
|
|
|
227
212
|
/**
|
|
228
213
|
* Simple bind, faster than native
|
|
@@ -230,7 +215,7 @@
|
|
|
230
215
|
function bind(fn /*: Function */, ctx /*: Object */) {
|
|
231
216
|
if (!fn) return false;
|
|
232
217
|
function boundFn(a) {
|
|
233
|
-
|
|
218
|
+
const l /*: number */ = arguments.length;
|
|
234
219
|
return l ? l > 1 ? fn.apply(ctx, arguments) : fn.call(ctx, a) : fn.call(ctx);
|
|
235
220
|
}
|
|
236
221
|
// record original fn length
|
|
@@ -244,7 +229,7 @@
|
|
|
244
229
|
if (!obj) {
|
|
245
230
|
return defaultValue;
|
|
246
231
|
}
|
|
247
|
-
|
|
232
|
+
let props, prop;
|
|
248
233
|
if (Array.isArray(propsArg)) {
|
|
249
234
|
props = propsArg.slice(0);
|
|
250
235
|
}
|
|
@@ -252,7 +237,7 @@
|
|
|
252
237
|
props = propsArg.replace(/\[(.+?)\]/g, '.$1');
|
|
253
238
|
props = props.split('.');
|
|
254
239
|
}
|
|
255
|
-
if (
|
|
240
|
+
if (typeof propsArg === 'symbol') {
|
|
256
241
|
props = [propsArg];
|
|
257
242
|
}
|
|
258
243
|
if (!Array.isArray(props)) {
|
|
@@ -275,14 +260,14 @@
|
|
|
275
260
|
props = props.replace(/\[(.+?)\]/g, '.$1');
|
|
276
261
|
props = props.split('.');
|
|
277
262
|
}
|
|
278
|
-
if (
|
|
263
|
+
if (typeof props === 'symbol') {
|
|
279
264
|
props = [props];
|
|
280
265
|
}
|
|
281
|
-
|
|
266
|
+
const lastProp = props.pop();
|
|
282
267
|
if (!lastProp) {
|
|
283
268
|
return false;
|
|
284
269
|
}
|
|
285
|
-
|
|
270
|
+
let thisProp;
|
|
286
271
|
while (thisProp = props.shift()) {
|
|
287
272
|
if (typeof obj[thisProp] === 'undefined') {
|
|
288
273
|
obj[thisProp] = {};
|
|
@@ -290,12 +275,12 @@
|
|
|
290
275
|
// 直接按路径修改 this.state 可能会导致 nextProps 也被修改
|
|
291
276
|
// 因此按路径寻找时,每一层都复制一遍
|
|
292
277
|
if (Array.isArray(obj[thisProp])) {
|
|
293
|
-
obj[thisProp] =
|
|
294
|
-
} else if (
|
|
278
|
+
obj[thisProp] = [...obj[thisProp]];
|
|
279
|
+
} else if (typeof obj[thisProp] === 'object') {
|
|
295
280
|
obj[thisProp] = Object.assign({}, obj[thisProp]);
|
|
296
281
|
}
|
|
297
282
|
obj = obj[thisProp];
|
|
298
|
-
if (!obj ||
|
|
283
|
+
if (!obj || typeof obj !== 'object') {
|
|
299
284
|
return false;
|
|
300
285
|
}
|
|
301
286
|
}
|
|
@@ -305,26 +290,24 @@
|
|
|
305
290
|
function report(msg) {
|
|
306
291
|
console.warn('[Taro Convert Warning] ' + msg);
|
|
307
292
|
}
|
|
308
|
-
|
|
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 语法重构。']]);
|
|
309
294
|
function flattenBehaviors(behavior, behaviorMap) {
|
|
310
295
|
if (typeof behavior === 'string') {
|
|
311
|
-
return report(
|
|
296
|
+
return report(`不支持使用内置 Behavior: [${behavior}]`);
|
|
312
297
|
}
|
|
313
|
-
|
|
298
|
+
const subBehaviors = behavior.behaviors;
|
|
314
299
|
if (subBehaviors === null || subBehaviors === void 0 ? void 0 : subBehaviors.length) {
|
|
315
|
-
subBehaviors.forEach(
|
|
316
|
-
return flattenBehaviors(subBehavior, behaviorMap);
|
|
317
|
-
});
|
|
300
|
+
subBehaviors.forEach(subBehavior => flattenBehaviors(subBehavior, behaviorMap));
|
|
318
301
|
}
|
|
319
|
-
Object.keys(behavior).forEach(
|
|
302
|
+
Object.keys(behavior).forEach(key => {
|
|
320
303
|
// 不支持的属性
|
|
321
304
|
if (nonsupport.has(key)) {
|
|
322
|
-
|
|
305
|
+
const advise = nonsupport.get(key);
|
|
323
306
|
return report(advise);
|
|
324
307
|
}
|
|
325
308
|
if (behaviorMap.has(key)) {
|
|
326
|
-
|
|
327
|
-
|
|
309
|
+
const list = behaviorMap.get(key);
|
|
310
|
+
const value = behavior[key];
|
|
328
311
|
list.push(value);
|
|
329
312
|
}
|
|
330
313
|
});
|
|
@@ -333,21 +316,21 @@
|
|
|
333
316
|
/**
|
|
334
317
|
* 该模块仅存放 convert 转换时用到的工具函数或变量
|
|
335
318
|
*/
|
|
336
|
-
|
|
319
|
+
const cacheOptions = {
|
|
337
320
|
cacheOptions: {},
|
|
338
|
-
setOptionsToCache: function
|
|
321
|
+
setOptionsToCache: function (options) {
|
|
339
322
|
if (Object.keys(options).length !== 0) {
|
|
340
323
|
this.cacheOptions = options;
|
|
341
324
|
}
|
|
342
325
|
},
|
|
343
|
-
getOptionsFromCache: function
|
|
326
|
+
getOptionsFromCache: function () {
|
|
344
327
|
return this.cacheOptions;
|
|
345
328
|
}
|
|
346
329
|
};
|
|
347
330
|
function toCamelCase(s) {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
for (
|
|
331
|
+
let camel = '';
|
|
332
|
+
let nextCap = false;
|
|
333
|
+
for (let i = 0; i < s.length; i++) {
|
|
351
334
|
if (s[i] !== '-') {
|
|
352
335
|
camel += nextCap ? s[i].toUpperCase() : s[i];
|
|
353
336
|
nextCap = false;
|
|
@@ -357,41 +340,39 @@
|
|
|
357
340
|
}
|
|
358
341
|
return camel;
|
|
359
342
|
}
|
|
360
|
-
|
|
343
|
+
const convertToArray = function (value, fn) {
|
|
361
344
|
if (value instanceof Array) {
|
|
362
345
|
return value.map(fn);
|
|
363
346
|
} else if (typeof value === 'number') {
|
|
364
347
|
return Array.from({
|
|
365
348
|
length: value
|
|
366
|
-
},
|
|
367
|
-
return index;
|
|
368
|
-
}).map(fn);
|
|
349
|
+
}, (_, index) => index).map(fn);
|
|
369
350
|
} else if (typeof value === 'string') {
|
|
370
351
|
return Array.from(value).map(fn);
|
|
371
|
-
} else if (
|
|
372
|
-
|
|
352
|
+
} else if (typeof value === 'object' && value !== null && Object.getPrototypeOf(value) === Object.prototype) {
|
|
353
|
+
const result = Object.keys(value).map(item => {
|
|
373
354
|
return fn(value[item], item);
|
|
374
355
|
});
|
|
375
356
|
return result;
|
|
376
357
|
}
|
|
377
358
|
};
|
|
378
|
-
|
|
359
|
+
const getTarget = (target, Taro) => {
|
|
379
360
|
if (!target) {
|
|
380
361
|
return {
|
|
381
362
|
dataset: {}
|
|
382
363
|
};
|
|
383
364
|
}
|
|
384
|
-
if (Taro.getEnv() === Taro.ENV_TYPE.
|
|
365
|
+
if (Taro.getEnv() === Taro.ENV_TYPE.HARMONYHYBRID || Taro.getEnv() === Taro.ENV_TYPE.WEB) {
|
|
385
366
|
if (target.fullDataset) {
|
|
386
367
|
return {
|
|
387
368
|
dataset: target.fullDataset
|
|
388
369
|
};
|
|
389
370
|
}
|
|
390
|
-
|
|
371
|
+
const fullDataset = {};
|
|
391
372
|
// 获取元素的所有属性
|
|
392
|
-
|
|
373
|
+
const targetAttrKeys = Object.keys(target);
|
|
393
374
|
// 遍历所有属性
|
|
394
|
-
for (
|
|
375
|
+
for (let i = 0; i < targetAttrKeys.length; i++) {
|
|
395
376
|
if (targetAttrKeys[i].startsWith('data-')) {
|
|
396
377
|
fullDataset[toCamelCase(targetAttrKeys[i].replace(/^data-/, '').toLowerCase())] = target[targetAttrKeys[i]];
|
|
397
378
|
}
|
|
@@ -404,16 +385,11 @@
|
|
|
404
385
|
return target;
|
|
405
386
|
};
|
|
406
387
|
|
|
407
|
-
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; } } }; }
|
|
408
|
-
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); }
|
|
409
|
-
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; }
|
|
410
|
-
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); }; }
|
|
411
|
-
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; } }
|
|
412
388
|
function defineGetter(component, key, getter) {
|
|
413
389
|
Object.defineProperty(component, key, {
|
|
414
390
|
enumerable: true,
|
|
415
391
|
configurable: true,
|
|
416
|
-
get:
|
|
392
|
+
get: () => {
|
|
417
393
|
if (getter === 'props') {
|
|
418
394
|
return component.props;
|
|
419
395
|
}
|
|
@@ -425,38 +401,38 @@
|
|
|
425
401
|
}
|
|
426
402
|
});
|
|
427
403
|
}
|
|
404
|
+
|
|
428
405
|
function propToState(newValue, _oldValue, key) {
|
|
429
406
|
this.state[key] = newValue;
|
|
430
407
|
}
|
|
431
408
|
function isFunction(o) {
|
|
432
409
|
return typeof o === 'function';
|
|
433
410
|
}
|
|
434
|
-
function withWeapp(weappConf) {
|
|
435
|
-
|
|
436
|
-
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) {
|
|
437
413
|
report('withWeapp 请传入“App/页面/组件“的配置对象。如果原生写法使用了基类,请将基类组合后的配置对象传入,详情请参考文档。');
|
|
438
414
|
}
|
|
439
|
-
return
|
|
415
|
+
return ConnectComponent => {
|
|
440
416
|
var _a;
|
|
441
|
-
|
|
442
|
-
|
|
417
|
+
const behaviorMap = new Map([['properties', []], ['data', []], ['methods', []], ['created', []], ['attached', []], ['ready', []], ['detached', []], ['lifetimes', []]]);
|
|
418
|
+
const behaviorProperties = {};
|
|
443
419
|
if ((_a = weappConf.behaviors) === null || _a === void 0 ? void 0 : _a.length) {
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
420
|
+
const {
|
|
421
|
+
behaviors
|
|
422
|
+
} = weappConf;
|
|
423
|
+
behaviors.forEach(behavior => flattenBehaviors(behavior, behaviorMap));
|
|
424
|
+
const propertiesList = behaviorMap.get('properties');
|
|
449
425
|
if (propertiesList.length) {
|
|
450
|
-
propertiesList.forEach(
|
|
426
|
+
propertiesList.forEach(property => {
|
|
451
427
|
Object.assign(behaviorProperties, property);
|
|
452
428
|
});
|
|
453
|
-
Object.keys(behaviorProperties).forEach(
|
|
454
|
-
|
|
429
|
+
Object.keys(behaviorProperties).forEach(propName => {
|
|
430
|
+
const propValue = behaviorProperties[propName];
|
|
455
431
|
if (!weappConf.properties) {
|
|
456
432
|
weappConf.properties = {};
|
|
457
433
|
}
|
|
458
434
|
if (!weappConf.properties.hasOwnProperty(propName)) {
|
|
459
|
-
if (propValue &&
|
|
435
|
+
if (propValue && typeof propValue === 'object' && propValue.value) {
|
|
460
436
|
propValue.value = clone(propValue.value);
|
|
461
437
|
}
|
|
462
438
|
weappConf.properties[propName] = propValue;
|
|
@@ -464,45 +440,38 @@
|
|
|
464
440
|
});
|
|
465
441
|
}
|
|
466
442
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
var _this;
|
|
472
|
-
_classCallCheck__default["default"](this, BaseComponent);
|
|
473
|
-
_this = _super.call(this, props);
|
|
474
|
-
_this._observeProps = [];
|
|
443
|
+
class BaseComponent extends ConnectComponent {
|
|
444
|
+
constructor(props) {
|
|
445
|
+
super(props);
|
|
446
|
+
this._observeProps = [];
|
|
475
447
|
// mixins 可以多次调用生命周期
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
args[_key - 1] = arguments[_key];
|
|
487
|
-
}
|
|
488
|
-
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);
|
|
489
458
|
};
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
if (
|
|
493
|
-
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);
|
|
494
463
|
}
|
|
495
|
-
Object.keys(obj).forEach(
|
|
496
|
-
safeSet(
|
|
464
|
+
Object.keys(obj).forEach(key => {
|
|
465
|
+
safeSet(this.state, key, obj[key]);
|
|
497
466
|
});
|
|
498
|
-
|
|
499
|
-
|
|
467
|
+
this.setState(this.state, () => {
|
|
468
|
+
this.triggerObservers(this.state, oldState);
|
|
500
469
|
if (callback) {
|
|
501
|
-
callback.call(
|
|
470
|
+
callback.call(this);
|
|
502
471
|
}
|
|
503
472
|
});
|
|
504
473
|
};
|
|
505
|
-
|
|
474
|
+
this.triggerEvent = (eventName, detail, options) => {
|
|
506
475
|
if (options) {
|
|
507
476
|
report('triggerEvent 不支持事件选项。');
|
|
508
477
|
}
|
|
@@ -512,561 +481,467 @@
|
|
|
512
481
|
return match[1].toUpperCase();
|
|
513
482
|
});
|
|
514
483
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
for (
|
|
484
|
+
const props = this.props;
|
|
485
|
+
const dataset = {};
|
|
486
|
+
for (const key in props) {
|
|
518
487
|
if (!key.startsWith('data-')) continue;
|
|
519
488
|
dataset[key.replace(/^data-/, '')] = props[key];
|
|
520
489
|
}
|
|
521
|
-
|
|
490
|
+
const func = props[`on${eventName[0].toUpperCase()}${eventName.slice(1)}`];
|
|
522
491
|
if (isFunction(func)) {
|
|
523
|
-
func.call(
|
|
492
|
+
func.call(this, {
|
|
524
493
|
type: eventName,
|
|
525
|
-
detail
|
|
494
|
+
detail,
|
|
526
495
|
target: {
|
|
527
496
|
id: props.id || '',
|
|
528
|
-
dataset
|
|
497
|
+
dataset
|
|
529
498
|
},
|
|
530
499
|
currentTarget: {
|
|
531
500
|
id: props.id || '',
|
|
532
|
-
dataset
|
|
501
|
+
dataset
|
|
533
502
|
}
|
|
534
503
|
});
|
|
535
504
|
}
|
|
536
505
|
};
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
defineGetter(
|
|
550
|
-
defineGetter(
|
|
551
|
-
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');
|
|
552
520
|
}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
} else if (propValue.name === 'Number') {
|
|
574
|
-
properties[propKey] = 0;
|
|
575
|
-
} else {
|
|
576
|
-
properties[propKey] = null;
|
|
577
|
-
}
|
|
578
|
-
} else if (_typeof__default["default"](propValue) === 'object') {
|
|
579
|
-
// propValue为对象时
|
|
580
|
-
properties[propKey] = propValue.value;
|
|
581
|
-
if (propValue.observer) {
|
|
582
|
-
observers.push(propValue.observer);
|
|
583
|
-
}
|
|
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;
|
|
584
541
|
} else {
|
|
585
542
|
properties[propKey] = null;
|
|
586
543
|
}
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
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;
|
|
591
552
|
}
|
|
553
|
+
this._observeProps.push({
|
|
554
|
+
name: propKey,
|
|
555
|
+
observers: observers
|
|
556
|
+
});
|
|
592
557
|
}
|
|
593
|
-
this.state = Object.assign(Object.assign({}, properties), this.state);
|
|
594
558
|
}
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
switch (key) {
|
|
610
|
-
case 'created':
|
|
611
|
-
case 'attached':
|
|
612
|
-
case 'detached':
|
|
613
|
-
case 'ready':
|
|
614
|
-
list.forEach(function (fn) {
|
|
615
|
-
return _this2.initLifeCycles(key, fn);
|
|
616
|
-
});
|
|
617
|
-
break;
|
|
618
|
-
}
|
|
619
|
-
};
|
|
620
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
621
|
-
_loop();
|
|
622
|
-
}
|
|
623
|
-
} catch (err) {
|
|
624
|
-
_iterator.e(err);
|
|
625
|
-
} finally {
|
|
626
|
-
_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;
|
|
627
573
|
}
|
|
628
574
|
}
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
} else {
|
|
647
|
-
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);
|
|
648
592
|
}
|
|
649
|
-
|
|
593
|
+
} else {
|
|
594
|
+
this.state = Object.assign(Object.assign({}, confValue), this.state);
|
|
650
595
|
}
|
|
651
|
-
case 'properties':
|
|
652
|
-
this.initProps(Object.assign(behaviorProperties, confValue));
|
|
653
596
|
break;
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
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
|
+
}
|
|
658
631
|
}
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
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;
|
|
663
639
|
}
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
{
|
|
671
|
-
this.initLifeCycleListener('show', cb);
|
|
672
|
-
break;
|
|
673
|
-
}
|
|
674
|
-
case 'hide':
|
|
675
|
-
{
|
|
676
|
-
this.initLifeCycleListener('hide', cb);
|
|
677
|
-
break;
|
|
678
|
-
}
|
|
679
|
-
case 'resize':
|
|
680
|
-
{
|
|
681
|
-
report('不支持组件所在页面的生命周期 pageLifetimes.resize。');
|
|
682
|
-
break;
|
|
683
|
-
}
|
|
684
|
-
}
|
|
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);
|
|
685
646
|
}
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
// 优先使用 lifetimes 中定义的生命周期
|
|
690
|
-
if ((_b = options.lifetimes) === null || _b === void 0 ? void 0 : _b[confKey]) {
|
|
691
|
-
break;
|
|
692
|
-
}
|
|
693
|
-
var lifecycle = options[confKey];
|
|
694
|
-
this.initLifeCycles(confKey, lifecycle);
|
|
695
|
-
} else if (isFunction(confValue)) {
|
|
696
|
-
this[confKey] = bind(confValue, this);
|
|
697
|
-
if (isApp && !appOptions.includes(confKey)) {
|
|
698
|
-
this.defineProperty(this.taroGlobalData, confKey, this);
|
|
699
|
-
}
|
|
700
|
-
// 原生页面和 Taro 页面中共计只能定义一次的生命周期
|
|
701
|
-
if (uniquePageLifecycle.includes(confKey) && ConnectComponent.prototype[confKey]) {
|
|
702
|
-
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"));
|
|
703
|
-
}
|
|
704
|
-
} else {
|
|
705
|
-
this[confKey] = confValue;
|
|
706
|
-
if (isApp && !appOptions.includes(confKey)) {
|
|
707
|
-
this.defineProperty(this.taroGlobalData, confKey, this);
|
|
708
|
-
}
|
|
647
|
+
// 原生页面和 Taro 页面中共计只能定义一次的生命周期
|
|
648
|
+
if (uniquePageLifecycle.includes(confKey) && ConnectComponent.prototype[confKey]) {
|
|
649
|
+
report(`生命周期 ${confKey} 已在原生部分进行定义,React 部分的定义将不会被执行。`);
|
|
709
650
|
}
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
if ((_c = options.behaviors) === null || _c === void 0 ? void 0 : _c.length) {
|
|
715
|
-
var behaviorData = {};
|
|
716
|
-
var methods = {};
|
|
717
|
-
var _iterator2 = _createForOfIteratorHelper(behaviorMap.entries()),
|
|
718
|
-
_step2;
|
|
719
|
-
try {
|
|
720
|
-
var _loop2 = function _loop2() {
|
|
721
|
-
var _step2$value = _slicedToArray__default["default"](_step2.value, 2),
|
|
722
|
-
key = _step2$value[0],
|
|
723
|
-
list = _step2$value[1];
|
|
724
|
-
switch (key) {
|
|
725
|
-
case 'data':
|
|
726
|
-
[].concat(_toConsumableArray__default["default"](list), [_this2.state]).forEach(function (dataObject, index) {
|
|
727
|
-
Object.keys(dataObject).forEach(function (dataKey) {
|
|
728
|
-
var value = dataObject[dataKey];
|
|
729
|
-
var preValue = behaviorData[dataKey];
|
|
730
|
-
var valueType = _typeof__default["default"](value);
|
|
731
|
-
var preValueType = _typeof__default["default"](preValue);
|
|
732
|
-
if (valueType === 'object') {
|
|
733
|
-
if (!value) {
|
|
734
|
-
behaviorData[dataKey] = value;
|
|
735
|
-
} else if (preValueType !== 'object' || !preValueType || Array.isArray(value)) {
|
|
736
|
-
behaviorData[dataKey] = index === list.length ? value : clone(value);
|
|
737
|
-
} else {
|
|
738
|
-
var newVal = Object.assign({}, preValue, value);
|
|
739
|
-
behaviorData[dataKey] = index === list.length ? newVal : clone(newVal);
|
|
740
|
-
}
|
|
741
|
-
} else {
|
|
742
|
-
behaviorData[dataKey] = value;
|
|
743
|
-
}
|
|
744
|
-
});
|
|
745
|
-
});
|
|
746
|
-
_this2.state = behaviorData;
|
|
747
|
-
break;
|
|
748
|
-
case 'methods':
|
|
749
|
-
list.forEach(function (methodsObject) {
|
|
750
|
-
Object.assign(methods, methodsObject);
|
|
751
|
-
});
|
|
752
|
-
Object.keys(methods).forEach(function (methodName) {
|
|
753
|
-
if (!_this2[methodName]) {
|
|
754
|
-
var _method = methods[methodName];
|
|
755
|
-
_this2[methodName] = bind(_method, _this2);
|
|
756
|
-
}
|
|
757
|
-
});
|
|
758
|
-
break;
|
|
759
|
-
case 'lifetimes':
|
|
760
|
-
list.forEach(function (lifetimesObject) {
|
|
761
|
-
for (var _key4 in lifetimesObject) {
|
|
762
|
-
_this2.initLifeCycles(_key4, lifetimesObject[_key4]);
|
|
763
|
-
}
|
|
764
|
-
});
|
|
765
|
-
break;
|
|
766
|
-
default:
|
|
767
|
-
break;
|
|
651
|
+
} else {
|
|
652
|
+
this[confKey] = confValue;
|
|
653
|
+
if (isApp && !appOptions.includes(confKey)) {
|
|
654
|
+
this.defineProperty(this.taroGlobalData, confKey, this);
|
|
768
655
|
}
|
|
769
|
-
};
|
|
770
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
771
|
-
_loop2();
|
|
772
656
|
}
|
|
773
|
-
|
|
774
|
-
_iterator2.e(err);
|
|
775
|
-
} finally {
|
|
776
|
-
_iterator2.f();
|
|
777
|
-
}
|
|
657
|
+
break;
|
|
778
658
|
}
|
|
779
659
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
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);
|
|
799
697
|
}
|
|
800
698
|
});
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
switch (lifecycleKey) {
|
|
810
|
-
case TaroLifeCycles.DidHide:
|
|
811
|
-
this.didHides.push(lifecycle);
|
|
812
|
-
break;
|
|
813
|
-
case TaroLifeCycles.DidMount:
|
|
814
|
-
this.didMounts.push(lifecycle);
|
|
815
|
-
break;
|
|
816
|
-
case TaroLifeCycles.DidShow:
|
|
817
|
-
this.didShows.push(lifecycle);
|
|
818
|
-
break;
|
|
819
|
-
case TaroLifeCycles.WillMount:
|
|
820
|
-
this.willMounts.push(lifecycle);
|
|
821
|
-
break;
|
|
822
|
-
case TaroLifeCycles.WillUnmount:
|
|
823
|
-
this.willUnmounts.push(lifecycle);
|
|
824
|
-
break;
|
|
825
|
-
}
|
|
826
|
-
}
|
|
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;
|
|
827
707
|
}
|
|
828
708
|
}
|
|
829
|
-
// mixins 不会覆盖已经设置的生命周期,加入到 this 是为了形如 this.created() 的调用
|
|
830
|
-
if (!isFunction(this[lifecycleName])) {
|
|
831
|
-
this[lifecycleName] = lifecycle;
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
}, {
|
|
835
|
-
key: "initLifeCycleListener",
|
|
836
|
-
value: function initLifeCycleListener(name, cb) {
|
|
837
|
-
// 组件的 ready、show、hide 需要利用页面事件触发
|
|
838
|
-
var router = this.current.router;
|
|
839
|
-
var lifecycleName = "on".concat(name[0].toUpperCase()).concat(name.slice(1));
|
|
840
|
-
cb = cb.bind(this);
|
|
841
|
-
(router === null || router === void 0 ? void 0 : router[lifecycleName]) && taro.eventCenter.on(router[lifecycleName], cb);
|
|
842
|
-
// unMount 时需要取消事件监听
|
|
843
|
-
this.eventDestroyList.push(function () {
|
|
844
|
-
return taro.eventCenter.off(router[lifecycleName], cb);
|
|
845
|
-
});
|
|
846
709
|
}
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
for (var i = 0; i < funcs.length; i++) {
|
|
854
|
-
var func = funcs[i];
|
|
855
|
-
this.safeExecute.apply(this, [func].concat(args));
|
|
856
|
-
}
|
|
710
|
+
}
|
|
711
|
+
initLifeCycles(lifecycleName, lifecycle) {
|
|
712
|
+
// 不支持的生命周期
|
|
713
|
+
if (nonsupport.has(lifecycleName)) {
|
|
714
|
+
const advise = nonsupport.get(lifecycleName);
|
|
715
|
+
return report(advise);
|
|
857
716
|
}
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
var prop = prevProps === null || prevProps === void 0 ? void 0 : prevProps[key];
|
|
866
|
-
var nextProp = nextProps[key];
|
|
867
|
-
// 小程序是深比较不同之后才 trigger observer
|
|
868
|
-
if (!isEqual(prop, nextProp)) {
|
|
869
|
-
observers.forEach(function (observer) {
|
|
870
|
-
if (typeof observer === 'string') {
|
|
871
|
-
var ob = _this4[observer];
|
|
872
|
-
if (isFunction(ob)) {
|
|
873
|
-
ob.call(_this4, nextProp, prop, key);
|
|
874
|
-
}
|
|
875
|
-
} else if (isFunction(observer)) {
|
|
876
|
-
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);
|
|
877
724
|
}
|
|
878
725
|
});
|
|
879
|
-
}
|
|
880
|
-
});
|
|
881
|
-
}
|
|
882
|
-
}, {
|
|
883
|
-
key: "triggerObservers",
|
|
884
|
-
value: function triggerObservers(current, prev) {
|
|
885
|
-
var observers = this.observers;
|
|
886
|
-
if (observers == null) {
|
|
887
|
-
return;
|
|
888
|
-
}
|
|
889
|
-
if (Object.keys(observers).length === 0) {
|
|
890
|
-
return;
|
|
891
|
-
}
|
|
892
|
-
var result = diff(current, prev);
|
|
893
|
-
var resultKeys = Object.keys(result);
|
|
894
|
-
if (resultKeys.length === 0) {
|
|
895
|
-
return;
|
|
896
|
-
}
|
|
897
|
-
for (var observerKey in observers) {
|
|
898
|
-
if (/\*\*/.test(observerKey)) {
|
|
899
|
-
report('数据监听器 observers 不支持使用通配符 **。');
|
|
900
|
-
continue;
|
|
901
|
-
}
|
|
902
|
-
var keys = observerKey.split(',').map(function (k) {
|
|
903
|
-
return k.trim();
|
|
904
726
|
});
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
var key = keys[i];
|
|
908
|
-
for (var j = 0; j < resultKeys.length; j++) {
|
|
909
|
-
var resultKey = resultKeys[j];
|
|
910
|
-
if (resultKey.startsWith(key) || key.startsWith(resultKey) && key.endsWith(']')) {
|
|
911
|
-
isModified = true;
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
if (isModified) {
|
|
916
|
-
observers[observerKey].apply(this, keys.map(function (key) {
|
|
917
|
-
return safeGet(current, key);
|
|
918
|
-
}));
|
|
919
|
-
}
|
|
727
|
+
} else {
|
|
728
|
+
this.initLifeCycleListener('ready', lifecycle);
|
|
920
729
|
}
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
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
|
+
}
|
|
933
751
|
}
|
|
934
|
-
});
|
|
935
|
-
}
|
|
936
|
-
}, {
|
|
937
|
-
key: "privateStopNoop",
|
|
938
|
-
value: function privateStopNoop() {
|
|
939
|
-
var e;
|
|
940
|
-
var fn;
|
|
941
|
-
if (arguments.length === 2) {
|
|
942
|
-
fn = arguments.length <= 0 ? undefined : arguments[0];
|
|
943
|
-
e = arguments.length <= 1 ? undefined : arguments[1];
|
|
944
|
-
} else if (arguments.length === 1) {
|
|
945
|
-
e = arguments.length <= 0 ? undefined : arguments[0];
|
|
946
752
|
}
|
|
947
|
-
if (e.type === 'touchmove') {
|
|
948
|
-
report('catchtouchmove 转换后只能停止回调函数的冒泡,不能阻止滚动穿透。如要阻止滚动穿透,可以手动给编译后的 View 组件加上 catchMove 属性');
|
|
949
|
-
}
|
|
950
|
-
e.stopPropagation();
|
|
951
|
-
isFunction(fn) && fn(e);
|
|
952
|
-
}
|
|
953
|
-
// ================ React 生命周期 ================
|
|
954
|
-
}, {
|
|
955
|
-
key: "componentWillMount",
|
|
956
|
-
value: function componentWillMount() {
|
|
957
|
-
this.safeExecute(_get__default["default"](_getPrototypeOf__default["default"](BaseComponent.prototype), "componentWillMount", this));
|
|
958
|
-
this.executeLifeCycles(this.willMounts, this.current.router || {});
|
|
959
|
-
this.triggerObservers(this.data, BaseComponent.defaultProps);
|
|
960
|
-
this.triggerPropertiesObservers(BaseComponent.defaultProps, this.props);
|
|
961
|
-
}
|
|
962
|
-
}, {
|
|
963
|
-
key: "componentDidMount",
|
|
964
|
-
value: function componentDidMount() {
|
|
965
|
-
this.safeExecute(_get__default["default"](_getPrototypeOf__default["default"](BaseComponent.prototype), "componentDidMount", this));
|
|
966
|
-
this.executeLifeCycles(this.didMounts);
|
|
967
|
-
}
|
|
968
|
-
}, {
|
|
969
|
-
key: "componentWillUnmount",
|
|
970
|
-
value: function componentWillUnmount() {
|
|
971
|
-
this.eventDestroyList.forEach(function (fn) {
|
|
972
|
-
return fn();
|
|
973
|
-
});
|
|
974
|
-
this.safeExecute(_get__default["default"](_getPrototypeOf__default["default"](BaseComponent.prototype), "componentWillUnmount", this));
|
|
975
|
-
this.executeLifeCycles(this.willUnmounts);
|
|
976
753
|
}
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
this.safeExecute(_get__default["default"](_getPrototypeOf__default["default"](BaseComponent.prototype), "componentDidHide", this));
|
|
981
|
-
this.executeLifeCycles(this.didHides);
|
|
754
|
+
// mixins 不会覆盖已经设置的生命周期,加入到 this 是为了形如 this.created() 的调用
|
|
755
|
+
if (!isFunction(this[lifecycleName])) {
|
|
756
|
+
this[lifecycleName] = lifecycle;
|
|
982
757
|
}
|
|
983
|
-
}
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
}
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
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);
|
|
995
774
|
}
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
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;
|
|
1001
802
|
}
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
get: function get() {
|
|
1005
|
-
return this.current.page.id;
|
|
803
|
+
if (Object.keys(observers).length === 0) {
|
|
804
|
+
return;
|
|
1006
805
|
}
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
return
|
|
806
|
+
const result = diff(current, prev);
|
|
807
|
+
const resultKeys = Object.keys(result);
|
|
808
|
+
if (resultKeys.length === 0) {
|
|
809
|
+
return;
|
|
1011
810
|
}
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
return taro.createMediaQueryObserver();
|
|
1027
|
-
} else {
|
|
1028
|
-
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
|
+
}
|
|
1029
825
|
}
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
value: function selectComponent() {
|
|
1035
|
-
report(nonsupport.get('selectComponent'));
|
|
1036
|
-
}
|
|
1037
|
-
}, {
|
|
1038
|
-
key: "selectAllComponents",
|
|
1039
|
-
value: function selectAllComponents() {
|
|
1040
|
-
report(nonsupport.get('selectAllComponents'));
|
|
826
|
+
}
|
|
827
|
+
if (isModified) {
|
|
828
|
+
observers[observerKey].apply(this, keys.map(key => safeGet(current, key)));
|
|
829
|
+
}
|
|
1041
830
|
}
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
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];
|
|
1046
852
|
}
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
value: function groupSetData() {
|
|
1050
|
-
report(nonsupport.get('groupSetData'));
|
|
853
|
+
if (e.type === 'touchmove') {
|
|
854
|
+
report('catchtouchmove 转换后只能停止回调函数的冒泡,不能阻止滚动穿透。如要阻止滚动穿透,可以手动给编译后的 View 组件加上 catchMove 属性');
|
|
1051
855
|
}
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
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;
|
|
1056
929
|
if (props) {
|
|
1057
|
-
for (
|
|
1058
|
-
|
|
930
|
+
for (const propKey in props) {
|
|
931
|
+
const propValue = props[propKey];
|
|
1059
932
|
if (propValue != null && !isFunction(propValue)) {
|
|
1060
933
|
if (propValue.value !== undefined) {
|
|
1061
934
|
// 如果是 null 也赋值到 defaultProps
|
|
1062
|
-
BaseComponent.defaultProps = Object.assign(
|
|
935
|
+
BaseComponent.defaultProps = Object.assign({
|
|
936
|
+
[propKey]: propValue.value
|
|
937
|
+
}, BaseComponent.defaultProps);
|
|
1063
938
|
}
|
|
1064
939
|
}
|
|
1065
940
|
}
|
|
1066
941
|
}
|
|
1067
|
-
|
|
1068
|
-
staticOptions.forEach(
|
|
1069
|
-
|
|
942
|
+
const staticOptions = ['externalClasses', 'relations', 'options'];
|
|
943
|
+
staticOptions.forEach(option => {
|
|
944
|
+
const value = weappConf[option];
|
|
1070
945
|
if (value != null) {
|
|
1071
946
|
BaseComponent[option] = value;
|
|
1072
947
|
}
|