@tarojs/with-weapp 4.0.0-canary.9 → 4.0.1-alpha.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 +8 -8
- package/dist/index.esm.js +847 -895
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +846 -908
- package/dist/index.js.map +1 -1
- package/dist/with-weapp.js +850 -901
- package/dist/with-weapp.js.map +1 -1
- package/package.json +18 -27
- package/src/index.ts +32 -10
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,889 +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
|
-
var subBehaviors = behavior.behaviors;
|
|
327
|
-
if (subBehaviors === null || subBehaviors === void 0 ? void 0 : subBehaviors.length) {
|
|
328
|
-
subBehaviors.forEach(function (subBehavior) {
|
|
329
|
-
return flattenBehaviors(subBehavior, behaviorMap);
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
Object.keys(behavior).forEach(function (key) {
|
|
333
|
-
// 不支持的属性
|
|
334
|
-
if (nonsupport.has(key)) {
|
|
335
|
-
var advise = nonsupport.get(key);
|
|
336
|
-
return report(advise);
|
|
335
|
+
if (typeof behavior === 'string') {
|
|
336
|
+
return report(`不支持使用内置 Behavior: [${behavior}]`);
|
|
337
337
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
list.push(value);
|
|
338
|
+
const subBehaviors = behavior.behaviors;
|
|
339
|
+
if (subBehaviors === null || subBehaviors === void 0 ? void 0 : subBehaviors.length) {
|
|
340
|
+
subBehaviors.forEach(subBehavior => flattenBehaviors(subBehavior, behaviorMap));
|
|
342
341
|
}
|
|
343
|
-
|
|
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
|
+
}
|
|
353
|
+
});
|
|
344
354
|
}
|
|
345
355
|
|
|
346
356
|
/**
|
|
347
357
|
* 该模块仅存放 convert 转换时用到的工具函数或变量
|
|
348
358
|
*/
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
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;
|
|
354
368
|
}
|
|
355
|
-
},
|
|
356
|
-
getOptionsFromCache: function getOptionsFromCache() {
|
|
357
|
-
return this.cacheOptions;
|
|
358
|
-
}
|
|
359
369
|
};
|
|
360
370
|
function toCamelCase(s) {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
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
|
+
}
|
|
369
381
|
}
|
|
370
|
-
|
|
371
|
-
return camel;
|
|
382
|
+
return camel;
|
|
372
383
|
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
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
|
+
}
|
|
390
402
|
};
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
dataset: {}
|
|
395
|
-
};
|
|
396
|
-
}
|
|
397
|
-
if (Taro.getEnv() === Taro.ENV_TYPE.HARMONYHYBRID || Taro.getEnv() === Taro.ENV_TYPE.WEB) {
|
|
398
|
-
if (target.fullDataset) {
|
|
399
|
-
return {
|
|
400
|
-
dataset: target.fullDataset
|
|
401
|
-
};
|
|
403
|
+
const getTarget = (target, Taro) => {
|
|
404
|
+
if (!target) {
|
|
405
|
+
return { dataset: {} };
|
|
402
406
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
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 };
|
|
411
422
|
}
|
|
412
|
-
target
|
|
413
|
-
return {
|
|
414
|
-
dataset: fullDataset
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
|
-
return target;
|
|
423
|
+
return target;
|
|
418
424
|
};
|
|
419
425
|
|
|
420
|
-
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; } } }; }
|
|
421
|
-
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); }
|
|
422
|
-
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; }
|
|
423
|
-
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); }; }
|
|
424
|
-
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; } }
|
|
425
426
|
function defineGetter(component, key, getter) {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
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
|
+
});
|
|
440
441
|
}
|
|
441
|
-
|
|
442
442
|
function propToState(newValue, _oldValue, key) {
|
|
443
|
-
|
|
443
|
+
this.state[key] = newValue;
|
|
444
444
|
}
|
|
445
445
|
function isFunction(o) {
|
|
446
|
-
|
|
446
|
+
return typeof o === 'function';
|
|
447
447
|
}
|
|
448
|
-
function withWeapp(weappConf) {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
report('withWeapp 请传入“App/页面/组件“的配置对象。如果原生写法使用了基类,请将基类组合后的配置对象传入,详情请参考文档。');
|
|
452
|
-
}
|
|
453
|
-
return function (ConnectComponent) {
|
|
454
|
-
var _a;
|
|
455
|
-
var behaviorMap = new Map([['properties', []], ['data', []], ['methods', []], ['created', []], ['attached', []], ['ready', []], ['detached', []], ['lifetimes', []]]);
|
|
456
|
-
var behaviorProperties = {};
|
|
457
|
-
if ((_a = weappConf.behaviors) === null || _a === void 0 ? void 0 : _a.length) {
|
|
458
|
-
var behaviors = weappConf.behaviors;
|
|
459
|
-
behaviors.forEach(function (behavior) {
|
|
460
|
-
return flattenBehaviors(behavior, behaviorMap);
|
|
461
|
-
});
|
|
462
|
-
var propertiesList = behaviorMap.get('properties');
|
|
463
|
-
if (propertiesList.length) {
|
|
464
|
-
propertiesList.forEach(function (property) {
|
|
465
|
-
Object.assign(behaviorProperties, property);
|
|
466
|
-
});
|
|
467
|
-
Object.keys(behaviorProperties).forEach(function (propName) {
|
|
468
|
-
var propValue = behaviorProperties[propName];
|
|
469
|
-
if (!weappConf.properties) {
|
|
470
|
-
weappConf.properties = {};
|
|
471
|
-
}
|
|
472
|
-
if (!weappConf.properties.hasOwnProperty(propName)) {
|
|
473
|
-
if (propValue && _typeof__default["default"](propValue) === 'object' && propValue.value) {
|
|
474
|
-
propValue.value = clone(propValue.value);
|
|
475
|
-
}
|
|
476
|
-
weappConf.properties[propName] = propValue;
|
|
477
|
-
}
|
|
478
|
-
});
|
|
479
|
-
}
|
|
448
|
+
function withWeapp(weappConf, isApp = false) {
|
|
449
|
+
if (typeof weappConf === 'object' && Object.keys(weappConf).length === 0) {
|
|
450
|
+
report('withWeapp 请传入“App/页面/组件“的配置对象。如果原生写法使用了基类,请将基类组合后的配置对象传入,详情请参考文档。');
|
|
480
451
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
if (callback) {
|
|
515
|
-
callback.call(_assertThisInitialized__default["default"](_this));
|
|
516
|
-
}
|
|
517
|
-
});
|
|
518
|
-
};
|
|
519
|
-
_this.triggerEvent = function (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
|
-
var props = _this.props;
|
|
530
|
-
var dataset = {};
|
|
531
|
-
for (var key in props) {
|
|
532
|
-
if (!key.startsWith('data-')) continue;
|
|
533
|
-
dataset[key.replace(/^data-/, '')] = props[key];
|
|
534
|
-
}
|
|
535
|
-
var func = props["on".concat(eventName[0].toUpperCase()).concat(eventName.slice(1))];
|
|
536
|
-
if (isFunction(func)) {
|
|
537
|
-
func.call(_assertThisInitialized__default["default"](_this), {
|
|
538
|
-
type: eventName,
|
|
539
|
-
detail: detail,
|
|
540
|
-
target: {
|
|
541
|
-
id: props.id || '',
|
|
542
|
-
dataset: dataset
|
|
543
|
-
},
|
|
544
|
-
currentTarget: {
|
|
545
|
-
id: props.id || '',
|
|
546
|
-
dataset: dataset
|
|
547
|
-
}
|
|
548
|
-
});
|
|
549
|
-
}
|
|
550
|
-
};
|
|
551
|
-
_this.hasBehavior = _this.componentMethodsProxy('hasBehavior');
|
|
552
|
-
_this.createSelectorQuery = _this.componentMethodsProxy('createSelectorQuery');
|
|
553
|
-
_this.createIntersectionObserver = _this.componentMethodsProxy('createIntersectionObserver');
|
|
554
|
-
_this.createMediaQueryObserver = _this.componentMethodsProxy('createMediaQueryObserver');
|
|
555
|
-
_this.getRelationNodes = _this.componentMethodsProxy('getRelationNodes');
|
|
556
|
-
_this.getTabBar = _this.componentMethodsProxy('getTabBar');
|
|
557
|
-
_this.getPageId = _this.componentMethodsProxy('getPageId');
|
|
558
|
-
_this.animate = _this.componentMethodsProxy('animate');
|
|
559
|
-
_this.clearAnimation = _this.componentMethodsProxy('clearAnimation');
|
|
560
|
-
_this.setUpdatePerformanceListener = _this.componentMethodsProxy('setUpdatePerformanceListener');
|
|
561
|
-
_this.state = _this.state || {};
|
|
562
|
-
_this.init(weappConf);
|
|
563
|
-
defineGetter(_assertThisInitialized__default["default"](_this), 'data', 'state');
|
|
564
|
-
defineGetter(_assertThisInitialized__default["default"](_this), 'properties', 'props');
|
|
565
|
-
return _this;
|
|
566
|
-
}
|
|
567
|
-
_createClass__default["default"](BaseComponent, [{
|
|
568
|
-
key: "initProps",
|
|
569
|
-
value: function initProps(props) {
|
|
570
|
-
var properties = {};
|
|
571
|
-
for (var propKey in props) {
|
|
572
|
-
if (props.hasOwnProperty(propKey)) {
|
|
573
|
-
var propValue = props[propKey];
|
|
574
|
-
// propValue 可能是 null, 构造函数, 对象
|
|
575
|
-
var observers = [propToState];
|
|
576
|
-
if (propValue === null || propValue === undefined) {
|
|
577
|
-
// propValue为null、undefined情况
|
|
578
|
-
properties[propKey] = null;
|
|
579
|
-
} else if (isFunction(propValue)) {
|
|
580
|
-
// propValue为Function,即Array、String、Boolean等情况时
|
|
581
|
-
if (propValue.name === 'Array') {
|
|
582
|
-
properties[propKey] = [];
|
|
583
|
-
} else if (propValue.name === 'String') {
|
|
584
|
-
properties[propKey] = '';
|
|
585
|
-
} else if (propValue.name === 'Boolean') {
|
|
586
|
-
properties[propKey] = false;
|
|
587
|
-
} else if (propValue.name === 'Number') {
|
|
588
|
-
properties[propKey] = 0;
|
|
589
|
-
} else {
|
|
590
|
-
properties[propKey] = null;
|
|
591
|
-
}
|
|
592
|
-
} else if (_typeof__default["default"](propValue) === 'object') {
|
|
593
|
-
// propValue为对象时
|
|
594
|
-
properties[propKey] = propValue.value;
|
|
595
|
-
if (propValue.observer) {
|
|
596
|
-
observers.push(propValue.observer);
|
|
597
|
-
}
|
|
598
|
-
} else {
|
|
599
|
-
properties[propKey] = null;
|
|
600
|
-
}
|
|
601
|
-
this._observeProps.push({
|
|
602
|
-
name: propKey,
|
|
603
|
-
observers: observers
|
|
604
|
-
});
|
|
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
|
+
});
|
|
605
485
|
}
|
|
606
|
-
}
|
|
607
|
-
this.state = Object.assign(Object.assign({}, properties), this.state);
|
|
608
486
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
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]);
|
|
630
511
|
});
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
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);
|
|
648
567
|
}
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
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
|
+
});
|
|
659
608
|
}
|
|
660
|
-
} else {
|
|
661
|
-
this.state = Object.assign(Object.assign({}, confValue), this.state);
|
|
662
|
-
}
|
|
663
|
-
break;
|
|
664
609
|
}
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
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
|
+
}
|
|
672
626
|
}
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
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
|
+
}
|
|
677
710
|
}
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
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
|
+
}
|
|
699
763
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
this.defineProperty(this.taroGlobalData, confKey, this);
|
|
722
|
-
}
|
|
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
|
+
}
|
|
723
785
|
}
|
|
724
|
-
break;
|
|
725
786
|
}
|
|
726
|
-
|
|
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
|
-
|
|
756
|
-
|
|
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
|
+
}
|
|
757
829
|
}
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
list.forEach(function (methodsObject) {
|
|
764
|
-
Object.assign(methods, methodsObject);
|
|
765
|
-
});
|
|
766
|
-
Object.keys(methods).forEach(function (methodName) {
|
|
767
|
-
if (!_this2[methodName]) {
|
|
768
|
-
var _method = methods[methodName];
|
|
769
|
-
_this2[methodName] = bind(_method, _this2);
|
|
770
|
-
}
|
|
771
|
-
});
|
|
772
|
-
break;
|
|
773
|
-
case 'lifetimes':
|
|
774
|
-
list.forEach(function (lifetimesObject) {
|
|
775
|
-
for (var _key4 in lifetimesObject) {
|
|
776
|
-
_this2.initLifeCycles(_key4, lifetimesObject[_key4]);
|
|
777
|
-
}
|
|
778
|
-
});
|
|
779
|
-
break;
|
|
780
|
-
default:
|
|
781
|
-
break;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
// mixins 不会覆盖已经设置的生命周期,加入到 this 是为了形如 this.created() 的调用
|
|
833
|
+
if (!isFunction(this[lifecycleName])) {
|
|
834
|
+
this[lifecycleName] = lifecycle;
|
|
782
835
|
}
|
|
783
|
-
};
|
|
784
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
785
|
-
_loop2();
|
|
786
|
-
}
|
|
787
|
-
} catch (err) {
|
|
788
|
-
_iterator2.e(err);
|
|
789
|
-
} finally {
|
|
790
|
-
_iterator2.f();
|
|
791
836
|
}
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
this.didMounts.push(function () {
|
|
806
|
-
var _this3 = this;
|
|
807
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key5 = 0; _key5 < _len2; _key5++) {
|
|
808
|
-
args[_key5] = arguments[_key5];
|
|
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);
|
|
809
850
|
}
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
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
|
+
}
|
|
814
870
|
});
|
|
815
|
-
});
|
|
816
|
-
} else {
|
|
817
|
-
this.initLifeCycleListener('ready', lifecycle);
|
|
818
871
|
}
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
switch (lifecycleKey) {
|
|
824
|
-
case TaroLifeCycles.DidHide:
|
|
825
|
-
this.didHides.push(lifecycle);
|
|
826
|
-
break;
|
|
827
|
-
case TaroLifeCycles.DidMount:
|
|
828
|
-
this.didMounts.push(lifecycle);
|
|
829
|
-
break;
|
|
830
|
-
case TaroLifeCycles.DidShow:
|
|
831
|
-
this.didShows.push(lifecycle);
|
|
832
|
-
break;
|
|
833
|
-
case TaroLifeCycles.WillMount:
|
|
834
|
-
this.willMounts.push(lifecycle);
|
|
835
|
-
break;
|
|
836
|
-
case TaroLifeCycles.WillUnmount:
|
|
837
|
-
this.willUnmounts.push(lifecycle);
|
|
838
|
-
break;
|
|
872
|
+
triggerObservers(current, prev) {
|
|
873
|
+
const observers = this.observers;
|
|
874
|
+
if (observers == null) {
|
|
875
|
+
return;
|
|
839
876
|
}
|
|
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
|
-
var func = funcs[i];
|
|
869
|
-
this.safeExecute.apply(this, [func].concat(args));
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
}, {
|
|
873
|
-
key: "triggerPropertiesObservers",
|
|
874
|
-
value: function triggerPropertiesObservers(prevProps, nextProps) {
|
|
875
|
-
var _this4 = this;
|
|
876
|
-
this._observeProps.forEach(function (_ref) {
|
|
877
|
-
var key = _ref.name,
|
|
878
|
-
observers = _ref.observers;
|
|
879
|
-
var prop = prevProps === null || prevProps === void 0 ? void 0 : prevProps[key];
|
|
880
|
-
var nextProp = nextProps[key];
|
|
881
|
-
// 小程序是深比较不同之后才 trigger observer
|
|
882
|
-
if (!isEqual(prop, nextProp)) {
|
|
883
|
-
observers.forEach(function (observer) {
|
|
884
|
-
if (typeof observer === 'string') {
|
|
885
|
-
var ob = _this4[observer];
|
|
886
|
-
if (isFunction(ob)) {
|
|
887
|
-
ob.call(_this4, nextProp, prop, key);
|
|
888
|
-
}
|
|
889
|
-
} else if (isFunction(observer)) {
|
|
890
|
-
observer.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
|
+
}
|
|
891
905
|
}
|
|
892
|
-
});
|
|
893
906
|
}
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
}
|
|
906
|
-
var result = diff(current, prev);
|
|
907
|
-
var resultKeys = Object.keys(result);
|
|
908
|
-
if (resultKeys.length === 0) {
|
|
909
|
-
return;
|
|
910
|
-
}
|
|
911
|
-
for (var observerKey in observers) {
|
|
912
|
-
if (/\*\*/.test(observerKey)) {
|
|
913
|
-
report('数据监听器 observers 不支持使用通配符 **。');
|
|
914
|
-
continue;
|
|
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
|
+
});
|
|
915
918
|
}
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
isModified = true;
|
|
919
|
+
privateStopNoop(...args) {
|
|
920
|
+
let e;
|
|
921
|
+
let fn;
|
|
922
|
+
if (args.length === 2) {
|
|
923
|
+
fn = args[0];
|
|
924
|
+
e = args[1];
|
|
925
|
+
}
|
|
926
|
+
else if (args.length === 1) {
|
|
927
|
+
e = args[0];
|
|
926
928
|
}
|
|
927
|
-
|
|
929
|
+
if (e.type === 'touchmove') {
|
|
930
|
+
report('catchtouchmove 转换后只能停止回调函数的冒泡,不能阻止滚动穿透。如要阻止滚动穿透,可以手动给编译后的 View 组件加上 catchMove 属性');
|
|
931
|
+
}
|
|
932
|
+
e.stopPropagation();
|
|
933
|
+
isFunction(fn) && fn(e);
|
|
928
934
|
}
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
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);
|
|
933
941
|
}
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
key: "defineProperty",
|
|
938
|
-
value: function defineProperty(target, key, data) {
|
|
939
|
-
Object.defineProperty(target, key, {
|
|
940
|
-
configurable: true,
|
|
941
|
-
enumerable: true,
|
|
942
|
-
set: function set(value) {
|
|
943
|
-
data[key] = value;
|
|
944
|
-
},
|
|
945
|
-
get: function get() {
|
|
946
|
-
return data[key];
|
|
942
|
+
componentDidMount() {
|
|
943
|
+
this.safeExecute(super.componentDidMount);
|
|
944
|
+
this.executeLifeCycles(this.didMounts);
|
|
947
945
|
}
|
|
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
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
this.safeExecute(_get__default["default"](_getPrototypeOf__default["default"](BaseComponent.prototype), "componentWillReceiveProps", this));
|
|
1009
|
-
}
|
|
1010
|
-
// ================ 小程序 App, Page, Component 实例属性与方法 ================
|
|
1011
|
-
}, {
|
|
1012
|
-
key: "is",
|
|
1013
|
-
get: function get() {
|
|
1014
|
-
return this.current.page.is;
|
|
1015
|
-
}
|
|
1016
|
-
}, {
|
|
1017
|
-
key: "id",
|
|
1018
|
-
get: function get() {
|
|
1019
|
-
return this.current.page.id;
|
|
1020
|
-
}
|
|
1021
|
-
}, {
|
|
1022
|
-
key: "dataset",
|
|
1023
|
-
get: function get() {
|
|
1024
|
-
return this.current.page.dataset;
|
|
1025
|
-
}
|
|
1026
|
-
}, {
|
|
1027
|
-
key: "componentMethodsProxy",
|
|
1028
|
-
value: function componentMethodsProxy(method) {
|
|
1029
|
-
var _this5 = this;
|
|
1030
|
-
return function () {
|
|
1031
|
-
var page = _this5.current.page;
|
|
1032
|
-
if (page === null || page === void 0 ? void 0 : page[method]) {
|
|
1033
|
-
return page[method].apply(page, arguments);
|
|
1034
|
-
} else if (method === 'createSelectorQuery') {
|
|
1035
|
-
return taro.createSelectorQuery();
|
|
1036
|
-
} else if (method === 'createIntersectionObserver') {
|
|
1037
|
-
// @ts-ignore
|
|
1038
|
-
return taro.createIntersectionObserver.apply(void 0, arguments);
|
|
1039
|
-
} else if (method === 'createMediaQueryObserver') {
|
|
1040
|
-
return taro.createMediaQueryObserver();
|
|
1041
|
-
} else {
|
|
1042
|
-
console.error("page \u4E0B\u6CA1\u6709 ".concat(method, " \u65B9\u6CD5"));
|
|
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'));
|
|
1043
1006
|
}
|
|
1044
|
-
};
|
|
1045
|
-
}
|
|
1046
|
-
}, {
|
|
1047
|
-
key: "selectComponent",
|
|
1048
|
-
value: function selectComponent() {
|
|
1049
|
-
report(nonsupport.get('selectComponent'));
|
|
1050
|
-
}
|
|
1051
|
-
}, {
|
|
1052
|
-
key: "selectAllComponents",
|
|
1053
|
-
value: function selectAllComponents() {
|
|
1054
|
-
report(nonsupport.get('selectAllComponents'));
|
|
1055
|
-
}
|
|
1056
|
-
}, {
|
|
1057
|
-
key: "selectOwnerComponent",
|
|
1058
|
-
value: function selectOwnerComponent() {
|
|
1059
|
-
report(nonsupport.get('selectOwnerComponent'));
|
|
1060
|
-
}
|
|
1061
|
-
}, {
|
|
1062
|
-
key: "groupSetData",
|
|
1063
|
-
value: function groupSetData() {
|
|
1064
|
-
report(nonsupport.get('groupSetData'));
|
|
1065
1007
|
}
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
BaseComponent.defaultProps = Object.assign(_defineProperty__default["default"]({}, propKey, propValue.value), BaseComponent.defaultProps);
|
|
1077
|
-
}
|
|
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
|
+
}
|
|
1078
1018
|
}
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
}
|
|
1088
|
-
return BaseComponent;
|
|
1089
|
-
};
|
|
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
|
+
};
|
|
1090
1028
|
}
|
|
1091
1029
|
|
|
1092
1030
|
exports.cacheOptions = cacheOptions;
|
|
1093
1031
|
exports.convertToArray = convertToArray;
|
|
1094
|
-
exports
|
|
1032
|
+
exports.default = withWeapp;
|
|
1095
1033
|
exports.getTarget = getTarget;
|
|
1096
1034
|
//# sourceMappingURL=index.js.map
|