anthonyshort / deku

Render interfaces using pure functions and virtual DOM
https://github.com/anthonyshort/deku/tree/master/docs
3.41k stars 130 forks source link

Question: redux integration #315

Closed rstacruz closed 8 years ago

rstacruz commented 8 years ago

Do I need to call subscribe() to keep my dom tree updated?

Can I use something other than redux as long as it implements .getState(), .subscribe() and dispatch()?

Should I use a 1 redux store for UI, and 1 other redux store for app data?

anthonyshort commented 8 years ago
  1. Yup, you'll do something like:
store.subscribe(() => updateUI())

Then just pass in the new store.getState() as either context or a prop.

  1. Yup, anything would work. It doesn't really care, it just needs some way to handle actions from the UI (dispatch) and then how you get state back into it is up to you (either as context, or a prop)
  2. For UI state you could just put it on the same store, there's no real harm in it. I'm assuming you're thinking for local component state. I can't think of any real reason why you couldn't just store it on your redux store though.
rstacruz commented 8 years ago

Cool :)

I investigated a little further and found a few things.

  1. You don't need anything redux-like at all. deku v2 will work without redux or anything to replace it.
  2. To replace redux, you just need to implement your own dispatch, which you'll pass onto dom.createRenderer. The only use of dispatch is to be consumed by your own components (so if you don't use dispatch, you don't need it).
  3. The main use of redux is to be passed as the second parameter to render(<Component />, store.getState()) (ie the context), which is simply an object passed onto every component in the tree. Your components are free to consume this context however it wants.