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