@tarojs/with-weapp 4.0.0-beta.7 → 4.0.0-beta.71

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