Skip to content

Commit

Permalink
Merge branch 'master' into refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Sep 6, 2016
2 parents 9348957 + 4c928f5 commit ab2c6a7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/createWCProto.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ export default (virtualDOMPatcher, component) => {
const {update, view, init, props = []} = component
return {

__dispatchActions (type) {
__dispatchActions (type, options = {}) {
if (!this.__handlers[type]) {
this.__handlers[type] = (params) =>
this.__handlers[type] = (params) => {
if (options.preventDefault) params.preventDefault()
if (options.stopPropagation) params.stopPropagation()
this.__store.dispatch({type, params})
}
}
return this.__handlers[type]
},
Expand Down
23 changes: 23 additions & 0 deletions test/test.createWCProto.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,26 @@ test('setProps', t => {
{type: '@@rwc/prop/B', params: {a: 1, b: 2}}
])
})
test('__dispatchActions({preventDefault: true})', t => {
const mockPatcher = createMockPatcher()
const mockEV = {preventDefault: spy()}
const attachShadow = () => '@ROOT'
const component = createMockComponent()
const wc = rwc.createWCProto(mockPatcher.patcher, component)
wc.attachShadow = attachShadow
wc.createdCallback()
wc.__dispatchActions('MOVE', {preventDefault: true})(mockEV)
t.true(mockEV.preventDefault.called)
})
test('__dispatchActions({stopPropagation: true})', t => {
const mockPatcher = createMockPatcher()
const mockEV = {stopPropagation: spy()}
const attachShadow = () => '@ROOT'
const component = createMockComponent()
const wc = rwc.createWCProto(mockPatcher.patcher, component)
wc.attachShadow = attachShadow
wc.createdCallback()
wc.__dispatchActions('MOVE', {stopPropagation: true})(mockEV)
t.true(mockEV.stopPropagation.called)
})

0 comments on commit ab2c6a7

Please sign in to comment.