Skip to content

Commit

Permalink
refactor(core): restructure event with a consistent name spacing
Browse files Browse the repository at this point in the history
each internal event is fired inside the @raf/* namespace

BREAKING CHANGE: rename all internal action types
  • Loading branch information
tusharmath committed Sep 6, 2016
1 parent d4e6a4e commit 9348957
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
9 changes: 5 additions & 4 deletions src/createWCProto.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default (virtualDOMPatcher, component) => {
},

attributeChangedCallback (name, old, params) {
this.__store.dispatch({type: `@@attr/${name}`, params})
this.__store.dispatch({type: `@@rwc/attr/${name}`, params})
},

createdCallback () {
Expand All @@ -64,22 +64,23 @@ export default (virtualDOMPatcher, component) => {
get: () => this.__props[p],
set: (params) => {
this.__props[p] = params
this.__store.dispatch({type: `@@prop/${p}`, params})
this.__store.dispatch({type: `@@rwc/prop/${p}`, params})
}
})
})

this.__patch = virtualDOMPatcher(this.attachShadow({mode: 'open'}))
this.__store = createStore(this.__reducer.bind(this), init(this))
this.__store.dispatch({type: '@@rwc/created'})
this.__render()
this.__dispose = this.__store.subscribe(this.__render)
},

attachedCallback () {
this.__store.dispatch({type: '@@attached', params: this})
this.__store.dispatch({type: '@@rwc/attached', params: this})
},

detachedCallback () {
this.__store.dispatch({type: '@@rwc/detached', params: this})
this.__dispose()
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/micro-redux.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@

'use strict'

const INIT = {type: '@@redux/INIT'}

export class Store {
constructor (reducer, state) {
this.__reducer = reducer
this.__state = state
this.__listeners = []
this.__dispatching = false
this.dispatch(INIT)
}

subscribe (listener) {
Expand Down
12 changes: 6 additions & 6 deletions test/test.createWCProto.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ test('attachedCallback()', t => {
wc.attachedCallback()

t.deepEqual(actions, [
{type: '@@redux/INIT'},
{type: '@@attached', params: wc}
{type: '@@rwc/created'},
{type: '@@rwc/attached', params: wc}
])
})
test('setProps', t => {
Expand All @@ -168,9 +168,9 @@ test('setProps', t => {
wc['B'] = {a: 1, b: 2}
wc['C'] = new Date()
t.deepEqual(actions, [
{type: '@@redux/INIT'},
{type: '@@attached', params: wc},
{type: '@@prop/A', params: 100},
{type: '@@prop/B', params: {a: 1, b: 2}}
{type: '@@rwc/created'},
{type: '@@rwc/attached', params: wc},
{type: '@@rwc/prop/A', params: 100},
{type: '@@rwc/prop/B', params: {a: 1, b: 2}}
])
})

0 comments on commit 9348957

Please sign in to comment.