Skip to content

Commit

Permalink
feat: Provide 'file_loader' to components through args
Browse files Browse the repository at this point in the history
  • Loading branch information
kantord committed Mar 24, 2018
1 parent f21dcbc commit 57b000b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/components/container_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ const ContainerComponent = (
.attr('class', wrapper_class)
const updated_definition = Object.assign({}, definition)
if (updated_definition.args === undefined) updated_definition.args = {}
if (args !== undefined)
if (args !== undefined) {
updated_definition.args.state_handler = args.state_handler
updated_definition.args.file_loader = args.file_loader
}
default_parser(updated_definition)(wrapper)
})
},
Expand Down
19 changes: 18 additions & 1 deletion src/components/container_base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,24 @@ describe('base container component', function() {
})
fake_parser.should.be.calledWith({
'component': sinon.match.any,
'args': {'state_handler': state_handler},
'args': {'state_handler': state_handler, 'file_loader': sinon.match.any},
'data': sinon.match.any,
})
})

it('passes on file_loader', () => {
const fake_parser = sinon.stub().returns(sinon.spy())
const file_loader = sinon.spy()
call_render_with({
'parser': fake_parser,
'component_args': {'title': '', 'file_loader': file_loader,},
'render_args': [
{ 'component': 'text', 'data': 'My title' },
]
})
fake_parser.should.be.calledWith({
'component': sinon.match.any,
'args': {'file_loader': file_loader, 'state_handler': sinon.match.any},
'data': sinon.match.any,
})
})
Expand Down
1 change: 1 addition & 0 deletions src/components/root/Root.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const RootComponent = Component({
if (data instanceof Array) data.map((definition) => {
const updated_definition = Object.assign({'args': {}}, definition)
updated_definition.args.state_handler = args.state_handler
updated_definition.args.file_loader = args.file_loader
default_parser(updated_definition)(body.append('div')
.attr('class', 'ds--wrapper'))
})
Expand Down

0 comments on commit 57b000b

Please sign in to comment.