Files: 4cecb64c5bfaa7e58358ce77e0af0153d7f224a2 / test / computed.js
960 bytesRaw
1 | require('setimmediate') |
2 | var test = require('tape') |
3 | |
4 | var computed = require('../computed') |
5 | var resolve = require('../resolve') |
6 | var Value = require('../value') |
7 | |
8 | test('computed get accessor', function(t) { |
9 | var value = Value(1) |
10 | var obs = computed(value, x => x * 100) |
11 | t.equal(resolve(obs), 100) |
12 | value.set(2) |
13 | t.equal(resolve(obs), 200) |
14 | t.end() |
15 | }) |
16 | |
17 | test('computed lazy watch', function(t) { |
18 | var value = Value(1) |
19 | var obs = computed(value, x => x * 100) |
20 | t.equal(resolve(obs), 100) |
21 | |
22 | var observedValues = [] |
23 | obs(x => observedValues.push(x)) |
24 | value.set(2) |
25 | t.deepEqual(observedValues, [200]) |
26 | |
27 | t.end() |
28 | }) |
29 | |
30 | test('computed lazy watch with `get` race condition', function(t) { |
31 | var value = Value(1) |
32 | var final = Value() |
33 | |
34 | var obs = computed(value, x => x * 100) |
35 | t.equal(resolve(obs), 100) |
36 | |
37 | value(x => { |
38 | resolve(obs) // resolve obs inside of observer |
39 | }) |
40 | |
41 | obs(final.set) |
42 | |
43 | value.set(2) |
44 | |
45 | t.deepEqual(resolve(final), 200) |
46 | t.end() |
47 | }) |
48 |
Built with git-ssb-web