1.3.4 • Published 7 years ago
memorux v1.3.4
Memorux
Minimalistic state container for your vqua components
Example
Step 1. Declare your store
class Cat {
constructor() {
this.state = {
say: null
}
}
dispatch(state, action) {
switch (action.name) {
case 'update': {
return action.data
break
}
default: {
return action.data
}
}
}
}
Step 2. Assign your stores
const memorux = require('memorux')
const memorux = new Memorux({ Cat })
memorux.store // => { Cat: { say: null } }
Step 3. Dispatch action
memorux.dispatch('Cat#update', { say: 'meow' })
// or
memorux.dispatch({
name: 'Cat#update',
data: { say: 'meow' }
})
// or
memorux.dispatch([
{
name: 'Cat#update',
data: { say: 'meow' }
},
])
Step 4. Listen changes
memorux.onChange(store =>
// store => { Cat: { say: 'meow' } }
)
Delayed actions
just return a promise like callback from your dispatch method
class Cat {
constructor() {
this.state = {
say: null
}
}
dispatch(state, action) {
switch (action.name) {
case 'update': {
return (resolve, reject) => {
setImmediate(() => {
resolve(action.data)
})
}
break
}
default: {
return action.data
}
}
}
}
Also, if you dispatch a few delayed actions you may need an event ending all of the actions, you can do so
memorux.dispatch([
// delayed action
// delayed action
// delayed action
]).then((store) => {
// do something with store
// after all actions ready
})
1.3.4
7 years ago
1.3.3
7 years ago
1.3.2
7 years ago
1.3.1
7 years ago
1.3.0
7 years ago
1.2.2
7 years ago
1.2.1
7 years ago
1.2.0
7 years ago
1.1.14
7 years ago
1.1.13
7 years ago
1.1.12
7 years ago
1.1.11
8 years ago
1.1.10
8 years ago
1.1.9
8 years ago
1.1.8
8 years ago
1.1.7
8 years ago
1.1.6
8 years ago
1.1.5
8 years ago
1.1.4
8 years ago
1.1.3
8 years ago
1.1.2
8 years ago
1.1.1
8 years ago
1.1.0
8 years ago
1.0.0
8 years ago