Files: 6c3600bdc8bb9caf695310b54e4b5f1ae61dad09 / test / archive / test-map.js
837 bytesRaw
1 | var Array = require('../array') |
2 | var Map = require('../map') |
3 | var Value = require('../value') |
4 | var computed = require('../computed') |
5 | |
6 | var value = Value('human') |
7 | var array = Array(['cat']) |
8 | var map = Map(array, function (obj) { |
9 | if (typeof obj === 'function') { |
10 | console.log('mapping => obs') |
11 | return computed([obj], (x) => x + ' [dynamic]') |
12 | } else { |
13 | console.log('mapping => ', obj) |
14 | return obj + ' [static]' |
15 | } |
16 | }) |
17 | |
18 | map(x => console.log(x)) |
19 | |
20 | array.push('dog') |
21 | array.push('cow') |
22 | array.push(value) |
23 | array.push('chicken') |
24 | array.push('wolf') |
25 | array.insert('sheep', 0) |
26 | value.set('monkey') |
27 | |
28 | // offline invalidate |
29 | var invalidator = Value(false) |
30 | var count = 0 |
31 | var thing = Map(Array(['cat']), function (obj, invalidateOn) { |
32 | invalidateOn(invalidator) |
33 | return count++ |
34 | }) |
35 | console.log(thing()) |
36 | invalidator.set(true) |
37 | console.log(thing()) |
38 |
Built with git-ssb-web