From 60dc2b03b05ad711ad8a64b58ea46fc79efd366a Mon Sep 17 00:00:00 2001 From: Tushar Mathur Date: Sat, 3 Sep 2016 19:44:37 +0530 Subject: [PATCH] feat(core): dispatch an action when createdCallback() is fired this could be used for getting additional DOM based metrics --- src/createWCProto.js | 4 ++++ test/test.createWCProto.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/createWCProto.js b/src/createWCProto.js index 2754e96..4c73ee1 100644 --- a/src/createWCProto.js +++ b/src/createWCProto.js @@ -62,6 +62,10 @@ export default (virtualDOMPatcher, component) => { this.__dispose = this.__store.subscribe(() => this.__render()) }, + attachedCallback () { + this.__dispatchActions('@@attached')(this) + }, + detachedCallback () { this.__dispose() } diff --git a/test/test.createWCProto.js b/test/test.createWCProto.js index bca6ad6..5181ca1 100644 --- a/test/test.createWCProto.js +++ b/test/test.createWCProto.js @@ -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} + ]) +})