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