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