Giter Club home page Giter Club logo

choo-store's People

Contributors

s3ththompson avatar toddself avatar ungoldman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

choo-store's Issues

Re-order event functions

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!

idea: export actions

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!

DOMContentLoaded hook?

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?

API design ideas

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)

tests

last but not least!

add support for nested state structures

something like

createStore({ storeName: 'settings.user' })
// => choo.state.settings.user

or maybe a separate prop?

createStore({ storeName: 'user', parent: 'settings' })
// => choo.state.settings.user

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.