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