git ssb

1+

Matt McKegg / mutant



Tree: bd426f70b20582a00fe0bfa9e1fca8d3d28f0acc

Files: bd426f70b20582a00fe0bfa9e1fca8d3d28f0acc / test / test-map.js

837 bytesRaw
1var Array = require('../array')
2var Map = require('../map')
3var Value = require('../value')
4var computed = require('../computed')
5
6var value = Value('human')
7var array = Array(['cat'])
8var 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
18map(x => console.log(x))
19
20array.push('dog')
21array.push('cow')
22array.push(value)
23array.push('chicken')
24array.push('wolf')
25array.insert('sheep', 0)
26value.set('monkey')
27
28// offline invalidate
29var invalidator = Value(false)
30var count = 0
31var thing = Map(Array(['cat']), function (obj, invalidateOn) {
32 invalidateOn(invalidator)
33 return count++
34})
35console.log(thing())
36invalidator.set(true)
37console.log(thing())
38

Built with git-ssb-web