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