-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jim de Beer
committed
May 31, 2016
1 parent
4add380
commit 26fe510
Showing
8 changed files
with
68 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use strict' | ||
require('./basic') | ||
require('./references') | ||
require('./switch') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
'use strict' | ||
const test = require('tape') | ||
const subsTest = require('../util') | ||
|
||
test('parent - $switch', function (t) { | ||
const subscription = { | ||
nest: { | ||
field: { | ||
$switch: { | ||
exec (state, type, stamp, subs, tree, sType) { | ||
console.log(state) | ||
if (state.key === 'a') { | ||
return 'optionA' | ||
} else if (state.key === 'b') { | ||
return 'optionB' | ||
} else if (state.key === 'c') { | ||
return 'optionC' | ||
} | ||
}, | ||
optionA: { $parent: { bla: { val: true } } }, | ||
optionB: { $parent: { $parent: { etc: { val: true } } } }, | ||
optionC: { val: true } // should fire wtf... | ||
} | ||
} | ||
} | ||
} | ||
|
||
const s = subsTest( | ||
t, | ||
{ | ||
etc: true, | ||
nest: { | ||
bla: { val: true }, | ||
a: {}, | ||
b: {}, | ||
c: 'hello', | ||
field: '$root.nest.a' | ||
} | ||
}, | ||
subscription | ||
) | ||
|
||
const r = s('initial subscription', [ { path: 'nest/bla', type: 'new' } ]) | ||
t.same(r.tree.nest.field.$switch.$c, { $parent: 'parent' }, 'got correct $c') | ||
s( | ||
'change to c (remove parent subs)', | ||
[ { path: 'nest/c', type: 'new' } ], | ||
{ nest: { field: '$root.nest.c' } } | ||
) | ||
t.equal(r.tree.nest.field.$switch.$c, void 0, 'removed field.$switch.$c') | ||
s( | ||
'change to b (double parent)', | ||
[ { path: 'etc', type: 'new' } ], | ||
{ nest: { field: '$root.nest.b' } } | ||
) | ||
s( | ||
'change to c (remove parent subs)', | ||
[ { path: 'nest/c', type: 'new' } ], | ||
{ nest: { field: '$root.nest.c' } } | ||
) | ||
t.equal(r.tree.nest.field.$switch.$c, void 0, 'removed field.$switch.$c') | ||
t.equal(r.tree.nest.field.$c, void 0, 'removed field.$c') | ||
t.end() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters