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