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