@@ -117,6 +117,30 @@ var __dep__ = '__dep__';
117
117
// 被框架占用的关键字,在 data 和 computed 中如果使用这些关键字,将会抛出错误
118
118
var reservedKeys = [ '$data' , '$emit' , '$computed' , __TUA_PATH__ ] ;
119
119
120
+ /**
121
+ * 统一的日志输出函数,在测试环境时不输出
122
+ * @param {String } type 输出类型 log|warn|error
123
+ * @param {any } out 具体的输出内容
124
+ */
125
+ var logByType = function logByType ( type ) {
126
+ return function ( ) {
127
+ var _console ;
128
+
129
+ for ( var _len = arguments . length , out = Array ( _len ) , _key = 0 ; _key < _len ; _key ++ ) {
130
+ out [ _key ] = arguments [ _key ] ;
131
+ }
132
+
133
+ /* istanbul ignore next */
134
+ ( _console = console ) [ type ] . apply ( _console , [ '[TUA-API]:' ] . concat ( out ) ) ;
135
+ } ;
136
+ } ;
137
+
138
+ var logger = {
139
+ log : logByType ( 'log' ) ,
140
+ warn : logByType ( 'warn' ) ,
141
+ error : logByType ( 'error' )
142
+ } ;
143
+
120
144
var isFn = function isFn ( fn ) {
121
145
return typeof fn === 'function' ;
122
146
} ;
@@ -142,6 +166,9 @@ var getPathByPrefix = function getPathByPrefix(prefix, key) {
142
166
return prefix === '' ? key : prefix + '.' + key ;
143
167
} ;
144
168
169
+ var jsonParse = JSON . parse . bind ( JSON ) ;
170
+ var stringify = JSON . stringify . bind ( JSON ) ;
171
+
145
172
/**
146
173
* 将 source 上的属性代理到 target 上
147
174
* @param {Object } source 被代理对象
@@ -203,7 +230,7 @@ var setObjByPath = function setObjByPath(_ref) {
203
230
) ;
204
231
} , 'this' ) ;
205
232
206
- error ( 'Property "' + cur + '" is not found in "' + parentStr + '": ' + 'Make sure that this property has initialized in the data option.' ) ;
233
+ logger . error ( 'Property "' + cur + '" is not found in "' + parentStr + '": ' + 'Make sure that this property has initialized in the data option.' ) ;
207
234
}
208
235
209
236
if ( idx === arr . length - 1 ) {
@@ -258,28 +285,6 @@ var assertType = function assertType(value, type) {
258
285
return { valid : valid , expectedType : expectedType } ;
259
286
} ;
260
287
261
- /**
262
- * 统一的日志输出函数,在测试环境时不输出
263
- * @param {String } type 输出类型 log|warn|error
264
- * @param {any } out 输出的内容
265
- */
266
- var logByType = function logByType ( type ) {
267
- return function ( ) {
268
- var _console ;
269
-
270
- for ( var _len = arguments . length , out = Array ( _len ) , _key = 0 ; _key < _len ; _key ++ ) {
271
- out [ _key ] = arguments [ _key ] ;
272
- }
273
-
274
- /* istanbul ignore next */
275
- ( _console = console ) [ type ] . apply ( _console , [ '[TUA-MP]:' ] . concat ( out ) ) ;
276
- } ;
277
- } ;
278
-
279
- var log = logByType ( 'log' ) ;
280
- var warn = logByType ( 'warn' ) ;
281
- var error = logByType ( 'error' ) ;
282
-
283
288
// reserved keys
284
289
var isReservedKeys = function isReservedKeys ( str ) {
285
290
return reservedKeys . indexOf ( str ) !== - 1 ;
@@ -358,7 +363,7 @@ var assertProp = function assertProp(_ref) {
358
363
}
359
364
360
365
if ( ! valid ) {
361
- warn ( 'Invalid prop: type check failed for prop "' + name + '".' + ( ' Expected ' + expectedTypes . join ( ', ' ) ) + ( ', got ' + toRawType ( value ) + '.' ) ) ;
366
+ logger . warn ( 'Invalid prop: type check failed for prop "' + name + '".' + ( ' Expected ' + expectedTypes . join ( ', ' ) ) + ( ', got ' + toRawType ( value ) + '.' ) ) ;
362
367
}
363
368
364
369
return valid ;
@@ -373,19 +378,15 @@ var assertProp = function assertProp(_ref) {
373
378
var getObserver = function getObserver ( name ) {
374
379
return function ( prop ) {
375
380
return function observer ( value ) {
376
- var _this = this ;
377
-
378
381
// 触发 setter
379
- Promise . resolve ( ) . then ( function ( ) {
380
- _this [ name ] = value ;
381
- } ) ;
382
+ this [ name ] = value ;
382
383
383
384
var valid = assertProp ( { prop : prop , name : name , value : value } ) ;
384
385
var validator = prop . validator ;
385
386
386
387
387
388
if ( validator && ! validator ( value ) ) {
388
- warn ( 'Invalid prop: custom validator check failed for prop "' + name + '".' ) ;
389
+ logger . warn ( 'Invalid prop: custom validator check failed for prop "' + name + '".' ) ;
389
390
return false ;
390
391
}
391
392
@@ -491,7 +492,7 @@ var hackSetData = function hackSetData(vm) {
491
492
} ) ;
492
493
} ;
493
494
494
- var version = "0.8.1 " ;
495
+ var version = "0.8.2 " ;
495
496
496
497
/**
497
498
* 根据 vm 生成 key
@@ -620,6 +621,10 @@ var VmStatus = function () {
620
621
// 更新数据
621
622
vm . updated ? setData . call ( vm , newState , vm . updated ) : setData . call ( vm , newState ) ;
622
623
624
+ // 干掉原生 setData 触发的 setter,不然会死循环
625
+ delete _this . newStateByVM [ vmKey ] ;
626
+ delete _this . oldStateByVM [ vmKey ] ;
627
+
623
628
// 触发 watch
624
629
Object . keys ( newState ) . map ( function ( key ) {
625
630
var newVal = newState [ key ] ;
@@ -1051,7 +1056,7 @@ var bindComputed = function bindComputed(vm, computed, asyncSetData) {
1051
1056
} ,
1052
1057
set : function set$$1 ( ) {
1053
1058
if ( typeof computed [ key ] . set === 'undefined' ) {
1054
- warn ( 'Computed property "' + key + '" was assigned to but it has no setter.' ) ;
1059
+ logger . warn ( 'Computed property "' + key + '" was assigned to but it has no setter.' ) ;
1055
1060
} else {
1056
1061
var setVal = computed [ key ] . set . bind ( vm ) ;
1057
1062
setVal . apply ( undefined , arguments ) ;
@@ -1264,6 +1269,6 @@ var TuaPage = function TuaPage(_ref) {
1264
1269
} ) ) ;
1265
1270
} ;
1266
1271
1267
- log ( 'Version ' + version ) ;
1272
+ logger . log ( 'Version ' + version ) ;
1268
1273
1269
1274
export { TuaComp , TuaPage } ;
0 commit comments