-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
elmaz - 690 bytes Elm-inspired state management #92
Comments
example 'use strict'
const createStore = require('elmaz')
const state = {
text: 'Hello',
name: 'Charlike',
}
const effects = {
changeBoth: ({ actions, dispatch, emit }, data, arg2) => {
actions.changeText({ welcome: data.text })
dispatch('changeName', data.name, arg2)
emit('someCustom',12, 'woohoo')
},
}
const reducers = {
// - ({ actions }, data, foo, arg3) -> actions.fooBar({ some: 'hi ' + data.name })
// - ({ dispatch, emit }, str, abc, arg3) -> dispatch('fooBar', { some: 'data' + str })
changeText: ({ emit, state, update }, data) => update({ text: data.welcome }),
changeName: ({ actions, state, update }, name, arg) => update({ name, arg }),
}
const store = createStore({ state, effects, reducers })
store.on('error', (er) => console.error('ER!', er))
store.on('action', (name) => console.log('action:', name))
store.on('stateUpdate', ({ prev, state, partial }) => {
console.log('prev:', prev)
console.log('state:', state)
console.log('partial:', partial)
console.log('====')
})
store.on('someCustom', (num, str) => {
console.log('custom event:', num, str)
})
store.actions.changeBoth({ text: 'Landing!', name: 'Jon Doe' }, 123)
// equivalent:
// store.dispatch('changeBoth', { text: 'Landing!', name: 'Jon Doe' }, 123)
console.log(store.state) |
https://github.com/tunnckoCore/elmaz
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
index.js
emitter.js
The text was updated successfully, but these errors were encountered: