-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathindex.js
1016 lines (955 loc) · 20.8 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
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
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import test from "tape"
import AsyncComputed from "../src"
import Vue from 'vue'
let baseErrorCallback = () => {
throw new Error('Unexpected error thrown')
}
const pluginOptions = {
errorHandler: msg => baseErrorCallback(msg),
}
Vue.use(AsyncComputed, pluginOptions)
test("Async computed values are computed", t => {
t.plan(4)
const vm = new Vue({
asyncComputed: {
a () {
return new Promise(resolve => {
setTimeout(() => resolve('done'), 10)
})
},
b () {
return new Promise(resolve => {
setTimeout(() => resolve(1337), 20)
})
}
}
})
t.equal(vm.a, null)
t.equal(vm.b, null)
vm.$watch('a', function (val) {
t.equal(val, 'done')
})
vm.$watch('b', function (val) {
t.equal(val, 1337)
})
})
test("An async computed value which is an pre-resolved promise updates at the next tick", t => {
t.plan(2)
const vm = new Vue({
asyncComputed: {
a () {
return Promise.resolve('done')
}
}
})
t.equal(vm.a, null)
Vue.nextTick(() => t.equal(vm.a, 'done'))
})
test("Sync and async computed data work together", t => {
t.plan(4)
const vm = new Vue({
asyncComputed: {
a () {
return new Promise(resolve => {
setTimeout(() => resolve('done'), 10)
})
}
},
computed: {
b () {
return 0
}
}
})
t.equal(vm.a, null)
t.equal(vm.b, 0)
vm.$watch('a', function (val) {
t.equal(val, 'done')
t.equal(vm.b, 0)
})
})
test("Async values are properly recalculated", t => {
t.plan(6)
const vm = new Vue({
asyncComputed: {
a () {
const data = this.x
return new Promise(resolve => {
setTimeout(() => resolve(data), 10)
})
},
b () {
return new Promise(resolve => {
setTimeout(() => resolve('done'), 40)
})
}
},
data: {
x: 0
}
})
t.equal(vm.a, null)
t.equal(vm.x, 0)
const unwatch = vm.$watch('a', function (val) {
t.equal(val, 0)
unwatch()
this.x = 1
t.equal(vm.a, 0)
vm.$watch('a', function (val) {
t.equal(val, 1)
})
})
vm.$watch('b', function (val) {
t.equal(val, 'done')
})
})
test("Old async values are properly invalidated", t => {
t.plan(2)
const vm = new Vue({
asyncComputed: {
a () {
return new Promise(resolve => {
setTimeout(() => resolve(this.waitTime), this.waitTime)
})
}
},
data: {
waitTime: 40
}
})
t.equal(vm.a, null)
setTimeout(() => { vm.waitTime = 10 }, 10)
vm.$watch('a', function (val) {
t.equal(val, 10) // Not 40, even though we don't cancel the $watch
})
})
test("Having only sync computed data still works", t => {
t.plan(2)
const vm = new Vue({
computed: {
a () {
return this.x
}
},
data: {
x: 2
}
})
t.equal(vm.a, 2)
vm.$watch('a', function (val) {
t.equal(val, 3)
})
vm.x++
})
test("Errors in computed properties are handled", t => {
t.plan(3)
const vm = new Vue({
asyncComputed: {
a () {
return Promise.reject(new Error('error'))
}
}
})
t.equal(vm.a, null)
pluginOptions.errorHandler = stack => {
t.equal(vm.a, null)
t.equal(stack.slice(0, 13), 'Error: error\n')
pluginOptions.errorHandler = baseErrorCallback
}
})
test("Errors in computed properties are handled, with useRawError", t => {
pluginOptions.useRawError = true
t.plan(3)
const vm = new Vue({
asyncComputed: {
a () {
// eslint-disable-next-line prefer-promise-reject-errors
return Promise.reject('error')
}
}
})
t.equal(vm.a, null)
pluginOptions.errorHandler = err => {
t.equal(vm.a, null)
t.equal(err, 'error')
pluginOptions.errorHandler = baseErrorCallback
pluginOptions.useRawError = false
}
})
test("Multiple asyncComputed objects are handled the same as normal computed property objects", t => {
t.plan(3)
const vm = new Vue({
mixins: [{
asyncComputed: {
a () {
return Promise.resolve('mixin-a')
},
b () {
return Promise.resolve('mixin-b')
}
}
}],
asyncComputed: {
a () {
return Promise.resolve('vm-a')
},
c () {
return Promise.resolve('vm-c')
}
}
})
Vue.nextTick(() => {
t.equal(vm.a, 'vm-a')
t.equal(vm.b, 'mixin-b')
t.equal(vm.c, 'vm-c')
})
})
test("Async computed values can have defaults", t => {
t.plan(6)
const vm = new Vue({
asyncComputed: {
x: {
default: false,
get () {
return Promise.resolve(true)
}
},
y () {
return Promise.resolve(true)
},
z: {
get () {
return Promise.resolve(true)
}
}
}
})
t.equal(vm.x, false, 'x should default to true')
t.equal(vm.y, null, 'y doesn\'t have a default')
t.equal(vm.z, null, 'z doesn\'t have a default despite being defined with an object')
Vue.nextTick(() => {
t.equal(vm.x, true, 'x resolves to true')
t.equal(vm.y, true, 'y resolves to true')
t.equal(vm.z, true, 'z resolves to true')
})
})
test("Default values can be functions", t => {
t.plan(4)
const vm = new Vue({
data: {
x: 1
},
asyncComputed: {
y: {
default () { return 2 },
get () {
return Promise.resolve(3)
}
},
z: {
default () { return this.x },
get () {
return Promise.resolve(4)
}
}
}
})
t.equal(vm.y, 2)
t.equal(vm.z, 1)
Vue.nextTick(() => {
t.equal(vm.y, 3)
t.equal(vm.z, 4)
})
})
test("Async computed values can be written to, and then will be properly overridden", t => {
t.plan(5)
const vm = new Vue({
data: {
x: 1
},
asyncComputed: {
y () {
this.y = this.x + 1
return new Promise(resolve => {
setTimeout(() => resolve(this.x), 10)
})
}
}
})
Vue.nextTick(() => {
t.equal(vm.y, 2)
const unwatch = vm.$watch('y', function (val) {
t.equal(val, 1)
unwatch()
vm.x = 4
t.equal(vm.y, 1)
Vue.nextTick(() => {
t.equal(vm.y, 5)
vm.$watch('y', function (val) {
t.equal(val, 4)
})
})
})
})
})
test("Watchers rerun the computation when a value changes", t => {
t.plan(4)
let i = 0
const vm = new Vue({
data: {
x: 0,
y: 2,
},
asyncComputed: {
z: {
get () {
return Promise.resolve(i + this.y)
},
watch () {
// eslint-disable-next-line no-unused-expressions
this.x
}
}
}
})
t.equal(vm.z, null)
Vue.nextTick(() => {
t.equal(vm.z, 2)
i++
vm.x--
Vue.nextTick(() => {
// This tick, Vue registers the change
// in the watcher, and reevaluates
// the getter function
t.equal(vm.z, 2)
Vue.nextTick(() => {
// Now in this tick the promise has
// resolved, and z is 3.
t.equal(vm.z, 3)
})
})
})
})
test("shouldUpdate controls when to rerun the computation when a value changes", t => {
t.plan(6)
let i = 0
const vm = new Vue({
data: {
x: 0,
y: 2,
},
asyncComputed: {
z: {
get () {
return Promise.resolve(i + this.y)
},
shouldUpdate () {
return this.x % 2 === 0
}
}
}
})
t.equal(vm.z, null)
Vue.nextTick(() => {
t.equal(vm.z, 2)
i++
// update x so it will be 1
// should update returns false now
vm.x++
Vue.nextTick(() => {
// This tick, Vue registers the change
// in the watcher, and reevaluates
// the getter function
t.equal(vm.z, 2)
Vue.nextTick(() => {
// Now in this tick the promise has
// resolved, and z is 2 since should update returned false.
t.equal(vm.z, 2)
// update x so it will be 2
// should update returns true now
vm.x++
Vue.nextTick(() => {
// This tick, Vue registers the change
// in the watcher, and reevaluates
// the getter function
t.equal(vm.z, 2)
Vue.nextTick(() => {
// Now in this tick the promise has
// resolved, and z is 3.
t.equal(vm.z, 3)
})
})
})
})
})
})
test("Watchers trigger but shouldUpdate can still block their updates", t => {
t.plan(6)
let i = 0
const vm = new Vue({
data: {
canUpdate: true,
x: 0,
y: 2,
},
asyncComputed: {
z: {
get () {
return Promise.resolve(i + this.y)
},
watch () {
// eslint-disable-next-line no-unused-expressions
this.x
},
shouldUpdate () {
return this.canUpdate
}
}
}
})
t.equal(vm.z, null)
Vue.nextTick(() => {
t.equal(vm.z, 2)
i++
vm.x--
Vue.nextTick(() => {
// This tick, Vue registers the change
// in the watcher, and reevaluates
// the getter function
t.equal(vm.z, 2)
Vue.nextTick(() => {
// Now in this tick the promise has
// resolved, and z is 3.
t.equal(vm.z, 3)
// We stop all updates from now on
vm.canUpdate = false
i++
vm.x--
Vue.nextTick(() => {
// This tick, Vue registers the change
// in the watcher, and reevaluates
// the getter function but no update
t.equal(vm.z, 3)
Vue.nextTick(() => {
// Now in this tick the promise has
// resolved, and z is still 3.
t.equal(vm.z, 3)
})
})
})
})
})
})
test("The default default value can be set in the plugin options", t => {
t.plan(2)
pluginOptions.default = 53
const vm = new Vue({
asyncComputed: {
x () {
return Promise.resolve(0)
}
}
})
t.equal(vm.x, 53)
Vue.nextTick(() => {
t.equal(vm.x, 0)
delete pluginOptions.default
})
})
test("The default default value can be set to undefined in the plugin options", t => {
t.plan(2)
pluginOptions.default = undefined
const vm = new Vue({
asyncComputed: {
x () {
return Promise.resolve(0)
}
}
})
t.equal(vm.x, undefined)
Vue.nextTick(() => {
t.equal(vm.x, 0)
delete pluginOptions.default
})
})
test("Handle an async computed value returning synchronously", t => {
t.plan(2)
const vm = new Vue({
asyncComputed: {
x () {
return 1
}
}
})
t.equal(vm.x, null)
Vue.nextTick(() => {
t.equal(vm.x, 1)
})
})
test("Work correctly with Vue.extend", t => {
t.plan(2)
const SubVue = Vue.extend({
asyncComputed: {
x () {
return Promise.resolve(1)
}
}
})
const vm = new SubVue({})
t.equal(vm.x, null)
Vue.nextTick(() => {
t.equal(vm.x, 1)
})
})
test("Async computed values can be calculated lazily", t => {
t.plan(7)
let called = false
const vm = new Vue({
asyncComputed: {
a: {
lazy: true,
get () {
called = true
return Promise.resolve(10)
}
}
}
})
t.equal(called, false)
Vue.nextTick(() => {
t.equal(called, false)
t.equal(vm.a, null)
t.equal(vm.a, null)
t.equal(called, false)
Vue.nextTick(() => {
t.equal(called, true)
Vue.nextTick(() => {
t.equal(vm.a, 10)
})
})
})
})
test("Async computed values aren't lazy with { lazy: false }", t => {
t.plan(4)
let called = false
const vm = new Vue({
asyncComputed: {
a: {
lazy: false,
get () {
called = true
return Promise.resolve(10)
}
}
}
})
t.equal(called, true)
t.equal(vm.a, null)
Vue.nextTick(() => {
t.equal(called, true)
t.equal(vm.a, 10)
})
})
test("Async computed values can be calculated lazily with a default", t => {
t.plan(7)
let called = false
const vm = new Vue({
asyncComputed: {
a: {
lazy: true,
default: 3,
get () {
called = true
return Promise.resolve(4)
}
}
}
})
t.equal(called, false)
Vue.nextTick(() => {
t.equal(called, false)
t.equal(vm.a, 3)
t.equal(vm.a, 3)
t.equal(called, false)
Vue.nextTick(() => {
t.equal(called, true)
Vue.nextTick(() => {
t.equal(vm.a, 4)
})
})
})
})
test("Underscore prefixes work (issue #33)", t => {
t.plan(4)
const vm = new Vue({
computed: {
sync_a () {
return 1
},
_sync_b () {
return 2
}
},
data () {
return { a_complete: false }
},
asyncComputed: {
_async_a () {
return new Promise(resolve => {
setTimeout(() => {
resolve(this.sync_a)
this.a_complete = true
}, 10)
})
},
async_b () {
return new Promise(resolve => {
setTimeout(() => resolve(this._sync_b), 10)
})
}
}
})
t.equal(vm._async_a, null)
t.equal(vm.async_b, null)
// _async_a is not reactive, because
// it begins with an underscore
// so we'll watch 'a_complete' to know once
// async_a has been computed.
vm.$watch('a_complete', function (val) {
t.equal(vm._async_a, 1)
})
vm.$watch('async_b', function (val) {
t.equal(val, 2)
})
})
test("shouldUpdate works with lazy", t => {
t.plan(8)
const vm = new Vue({
data: {
a: 0,
x: true,
y: false,
},
asyncComputed: {
b: {
lazy: true,
get () {
return Promise.resolve(this.a)
},
shouldUpdate () {
return this.x
}
},
c: {
lazy: true,
get () {
return Promise.resolve(this.a)
},
shouldUpdate () {
return this.y
}
}
}
})
Vue.nextTick(() => {
t.equal(vm.b, null)
t.equal(vm.c, null)
Vue.nextTick(() => {
Vue.nextTick(() => {
t.equal(vm.b, 0)
t.equal(vm.c, null)
vm.a++
Vue.nextTick(() => {
Vue.nextTick(() => {
t.equal(vm.b, 1)
t.equal(vm.c, null)
vm.x = false
vm.y = true
vm.a++
Vue.nextTick(() => {
Vue.nextTick(() => {
t.equal(vm.b, 1)
t.equal(vm.c, 2)
})
})
})
})
})
})
})
})
test("$asyncComputed is empty if there are no async computed properties", t => {
t.plan(1)
const vm = new Vue({
})
t.deepEqual(vm.$asyncComputed, {})
})
test("$asyncComputed[name] is created for all async computed properties", t => {
t.plan(15)
const vm = new Vue({
asyncComputed: {
a () {
return Promise.resolve(1)
},
b () {
return Promise.resolve(2)
}
}
})
t.deepEqual(Object.keys(vm.$asyncComputed), ['a', 'b'])
t.equal(vm.$asyncComputed['a'].state, 'updating')
t.equal(vm.$asyncComputed['b'].state, 'updating')
t.equal(vm.$asyncComputed['a'].updating, true)
t.equal(vm.$asyncComputed['a'].success, false)
t.equal(vm.$asyncComputed['a'].error, false)
t.equal(vm.$asyncComputed['a'].exception, null)
Vue.nextTick(() => {
t.equal(vm.a, 1)
t.equal(vm.b, 2)
t.equal(vm.$asyncComputed['a'].state, 'success')
t.equal(vm.$asyncComputed['b'].state, 'success')
t.equal(vm.$asyncComputed['a'].updating, false)
t.equal(vm.$asyncComputed['a'].success, true)
t.equal(vm.$asyncComputed['a'].error, false)
t.equal(vm.$asyncComputed['a'].exception, null)
})
})
test("$asyncComputed[name] handles errors and captures exceptions", t => {
t.plan(7)
const vm = new Vue({
asyncComputed: {
a () {
// eslint-disable-next-line prefer-promise-reject-errors
return Promise.reject('error-message')
}
}
})
t.equal(vm.$asyncComputed['a'].state, 'updating')
pluginOptions.errorHandler = stack => {
t.equal(vm.a, null)
t.equal(vm.$asyncComputed['a'].state, 'error')
t.equal(vm.$asyncComputed['a'].updating, false)
t.equal(vm.$asyncComputed['a'].success, false)
t.equal(vm.$asyncComputed['a'].error, true)
t.equal(vm.$asyncComputed['a'].exception, 'error-message')
pluginOptions.errorHandler = baseErrorCallback
}
})
test("$asyncComputed[name].update triggers re-evaluation", t => {
let valueToReturn = 1
t.plan(5)
const vm = new Vue({
asyncComputed: {
a () {
return new Promise(resolve => {
resolve(valueToReturn)
})
}
}
})
Vue.nextTick(() => {
t.equal(vm.a, 1)
valueToReturn = 2
t.equal(vm.$asyncComputed['a'].state, 'success')
vm.$asyncComputed['a'].update()
t.equal(vm.$asyncComputed['a'].state, 'updating')
Vue.nextTick(() => {
t.equal(vm.a, 2)
valueToReturn = 3
Vue.nextTick(() => {
t.equal(vm.a, 2)
})
})
})
})
test("$asyncComputed[name].update has the correct execution context", t => {
t.plan(8)
let addedValue = 1
const vm = new Vue({
data () {
return {
valueToReturn: 1,
}
},
asyncComputed: {
a () {
return new Promise(resolve => {
resolve(this.valueToReturn + addedValue)
})
},
b: {
get () {
return new Promise(resolve => {
resolve(this.valueToReturn + addedValue)
})
},
},
},
})
Vue.nextTick(() => {
// case 1: a is a function
t.equal(vm.a, 2)
t.equal(vm.$asyncComputed['a'].state, 'success')
// case 2: b is an object with a getter function
t.equal(vm.b, 2)
t.equal(vm.$asyncComputed['b'].state, 'success')
addedValue = 4
vm.$asyncComputed['a'].update()
t.equal(vm.$asyncComputed['a'].state, 'updating')
vm.$asyncComputed['b'].update()
t.equal(vm.$asyncComputed['b'].state, 'updating')
Vue.nextTick(() => {
t.equal(vm.a, 5)
t.equal(vm.b, 5)
})
})
})
test("Plain components with neither `data` nor `asyncComputed` still work (issue #50)", t => {
t.plan(1)
const vm = new Vue({
computed: {
a () {
return 1
}
}
})
t.equal(vm.a, 1)
})
test('Data of component still work as function and got vm', t => {
t.plan(1)
let _vmContext = null
const vm = new Vue({
data (vmContext) {
_vmContext = vmContext
},
asyncComputed: {
async a () {
return Promise.resolve(1)
},
},
})
t.equal(vm, _vmContext)
})
test("Watch as a function", t => {
t.plan(4)
let i = 0
const vm = new Vue({
data: {
y: 2,
obj: {
t: 0
}
},
asyncComputed: {
z: {
get () {
return Promise.resolve(i + this.y)
},
watch(){
this.obj.t
}
}
}
})
t.equal(vm.z, null)
Vue.nextTick(() => {
t.equal(vm.z, 2)
i++
vm.obj.t--
Vue.nextTick(() => {
// This tick, Vue registers the change
// in the watcher, and reevaluates
// the getter function
t.equal(vm.z, 2)
Vue.nextTick(() => {
// Now in this tick the promise has
// resolved, and z is 3.
t.equal(vm.z, 3)
})
})
})
})
test("Watchers as array with nested path rerun the computation when a value changes", t => {
t.plan(4)
let i = 0
const vm = new Vue({
data: {
y: 2,
obj: {
t: 0
}
},
asyncComputed: {
z: {
get () {
return Promise.resolve(i + this.y)
},
watch: ['obj.t']
}
}
})
t.equal(vm.z, null)
Vue.nextTick(() => {
t.equal(vm.z, 2)
i++
vm.obj.t--
Vue.nextTick(() => {
// This tick, Vue registers the change
// in the watcher, and reevaluates
// the getter function
t.equal(vm.z, 2)
Vue.nextTick(() => {
// Now in this tick the promise has
// resolved, and z is 3.
t.equal(vm.z, 3)
})
})
})
})
test("Watch as array with more then one value", t => {
t.plan(5)
let i = 0
const vm = new Vue({
data: {
y: 2,
obj: {
t: 0
},
r:0
},
asyncComputed: {
z: {
get () {
return Promise.resolve(i + this.y)
},
watch: ['obj.t', 'r']
}
}
})
t.equal(vm.z, null)
Vue.nextTick(() => {
t.equal(vm.z, 2)
i++
// checking for nested property
vm.obj.t--
Vue.nextTick(() => {
// This tick, Vue registers the change
// in the watcher, and reevaluates
// the getter function
t.equal(vm.z, 2)
Vue.nextTick(() => {