Skip to content

Commit

Permalink
feat(core): dispatch an action when createdCallback() is fired
Browse files Browse the repository at this point in the history
this could be used for getting additional DOM based metrics
  • Loading branch information
tusharmath committed Sep 3, 2016
1 parent 4010f2d commit 60dc2b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/createWCProto.js
Expand Up @@ -62,6 +62,10 @@ export default (virtualDOMPatcher, component) => {
this.__dispose = this.__store.subscribe(() => this.__render())
},

attachedCallback () {
this.__dispatchActions('@@attached')(this)
},

detachedCallback () {
this.__dispose()
}
Expand Down
15 changes: 15 additions & 0 deletions test/test.createWCProto.js
Expand Up @@ -139,3 +139,18 @@ test('attachShadow()', t => {
wc.createdCallback()
t.deepEqual(attachShadow.args, [[{mode: 'open'}]])
})
test('attachedCallback()', t => {
let actions = []
const mockPatcher = createMockPatcher()
const attachShadow = spy(() => '@ROOT')
const update = (s, a) => actions.push(a)
const wc = rwc.createWCProto(mockPatcher.patcher, createMockComponent({update}))
wc.attachShadow = attachShadow
wc.createdCallback()
wc.attachedCallback()

t.deepEqual(actions, [
{type: '@@redux/INIT'},
{type: '@@attached', params: wc}
])
})

0 comments on commit 60dc2b0

Please sign in to comment.