Skip to content

Commit ae0c3bc

Browse files
committed
fix: only root component gets its own state_handler
1 parent b50ba54 commit ae0c3bc

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/parser/parser.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const parse = (component_loader) => (input) => {
1010

1111
const component = component_loader(input.component)
1212
const args = Object.assign({}, input.args)
13-
args.state_handler = create_state_handler()
13+
if (input.component === 'root')
14+
args.state_handler = create_state_handler()
1415
const bind = component(args)
1516

1617
return (selection) => {

src/parser/parser.test.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,26 @@ describe('Parser', function() {
5555
component.should.be.a.Function()
5656
})
5757

58-
it('passes arguments to component', () => {
58+
it('passes state handler to root', () => {
5959
const fake_component = sinon.stub().returns(sinon.stub().returns(sinon.spy()))
6060
const fake_component_loader = sinon.stub().returns(fake_component)
6161
const my_selection = null
62-
const component = parse(fake_component_loader)({'component': 'foo', 'args': {'magic': 42}})
62+
const component = parse(fake_component_loader)({'component': 'root', 'args': {'title': ''}})
6363
component(my_selection)
64-
fake_component.should.be.calledWith({'magic': 42, 'state_handler': sinon.match.any})
64+
fake_component.should.be.calledWith({
65+
'title': '',
66+
'state_handler': fake_state_handler
67+
})
6568
})
6669

67-
it('passes state handler to root', () => {
70+
it('only passes state handler to root', () => {
6871
const fake_component = sinon.stub().returns(sinon.stub().returns(sinon.spy()))
6972
const fake_component_loader = sinon.stub().returns(fake_component)
7073
const my_selection = null
71-
const component = parse(fake_component_loader)({'component': 'root', 'args': {'title': ''}})
74+
const component = parse(fake_component_loader)({'component': 'text', 'args': {'tagName': 'p'}})
7275
component(my_selection)
7376
fake_component.should.be.calledWith({
74-
'title': '',
75-
'state_handler': fake_state_handler
77+
'tagName': 'p',
7678
})
7779
})
7880

0 commit comments

Comments
 (0)