choojs / choo-store Goto Github PK
View Code? Open in Web Editor NEWLightweight state structure for choo apps.
License: ISC License
Lightweight state structure for choo apps.
License: ISC License
This is awesome! Only thing which stood out to me is the prop ordering differs from choo. state, emitter
(choo) vs emitter, state
(choo-store). What are thoughts on restructuring that, and perhaps exposing app
as well?
function event (options, store, state, emitter, app) { }
Really awesome work!
Given
module.exports = createStore({
storeName: 'clicks',
initialState: { count: 0 },
events: {
increment: ({ store, emitter }) => {
store.count++
emitter.emit('render')
}
}
})
I could bind actions to the emitter and make those available for use elsewhere as store.actions[eventName]
. So once the store is registered with the app, you could do...
var { actions } = require('./stores/clicks')
module.exports = state => html`
<body>
<h1>count is ${state.clicks.count}</h1>
<button onclick=${() => actions.increment(1)}>Increment</button>
<button onclick=${() => actions.reset({ render: true })}>Reset</button>
</body>
`
Notice there is no longer any need for emit
in a component!
I frequently find myself wanting to do a little initialization, change some state, or trigger a store event on DOMContentLoaded
.
Would you consider providing some sort of hook from within the choo-store API to DOMContentLoaded
? Or is this best accomplished by a vanilla store that requires choo-store actions, listens for DOMContentLoaded
, and then fires them all off at once?
related: #8
module.exports = createStore({
name: 'abc.xyz',
store: { clicks: 0 },
actions: {
increment (num, { store, emitter }) {
store.clicks += num
emitter.emit('render')
}
}
})
produces
state: {
abc: {
xyz: {
clicks: 0
}
}
}
and
actions.increment(1) // emitter.emit('abc.xyz.increment', 1)
last but not least!
something like
createStore({ storeName: 'settings.user' })
// => choo.state.settings.user
or maybe a separate prop?
createStore({ storeName: 'user', parent: 'settings' })
// => choo.state.settings.user
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.