Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Upgrade useStore to useReducer-like API? #17

Open
dy opened this issue Dec 16, 2019 · 0 comments
Open

Upgrade useStore to useReducer-like API? #17

dy opened this issue Dec 16, 2019 · 0 comments

Comments

@dy
Copy link
Owner

dy commented Dec 16, 2019

Too often it is more useful to have in-place reducers/modifiers, rather than abstract actions.
Something like

let [store, { set, load, ... }] = useStore(initialState, actions)

But then actions may need to be rather reducers-like.

const devices = createStore('devices', {
  items: [],
  id: {},
  loading: false
}, {
  load: function * () {
    yield ({id: {}, loading: true, items: []})
    let result = await api.get(`/devices`)
    yield { items: result.payload, loading: false }
  },
  current: null
})

That creates following pattern, considering flowponents example as well.
Reactive generators can be applied to any objects as reducers - to DOM-objects as morphdom reducers, to store as store reducers, etc.

let devices = {}
createReducer(devices, devices => {
yield {...devices, a,b,c}
await ...load()
yield {...devices, d,e,f}
})

That's not far from just action though.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant