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} + ]) +})