Files: 384839d826d48b42af545900fe4d88c8df62357d / test / transaction.js
882 bytesRaw
1 | var test = require('tape') |
2 | var MutantArray = require('../array') |
3 | var MutantDict = require('../dict') |
4 | var MutantSet = require('../set') |
5 | |
6 | test(`array - transaction`, t => { |
7 | var array = MutantArray() |
8 | var changes = [] |
9 | array(x => changes.push(x)) |
10 | |
11 | array.transaction(() => { |
12 | array.push(1) |
13 | array.push(2) |
14 | array.push(3) |
15 | }) |
16 | |
17 | t.deepEqual(changes, [[1, 2, 3]]) |
18 | t.end() |
19 | }) |
20 | |
21 | test(`dict - transaction`, t => { |
22 | var dict = MutantDict() |
23 | var changes = [] |
24 | dict(x => changes.push(x)) |
25 | |
26 | dict.transaction(() => { |
27 | dict.put('a', 1) |
28 | dict.put('b', 2) |
29 | dict.put('c', 3) |
30 | }) |
31 | |
32 | t.deepEqual(changes, [{a: 1, b: 2, c: 3}]) |
33 | t.end() |
34 | }) |
35 | |
36 | test(`set - transaction`, t => { |
37 | var set = MutantSet() |
38 | var changes = [] |
39 | set(x => changes.push(x)) |
40 | |
41 | set.transaction(() => { |
42 | set.add(1) |
43 | set.add(2) |
44 | set.add(3) |
45 | }) |
46 | |
47 | t.deepEqual(changes, [[1, 2, 3]]) |
48 | t.end() |
49 | }) |
50 |
Built with git-ssb-web