arqex / freezer

A tree data structure that emits events on updates, even if the modification is triggered by one of the leaves, making it easier to think in a reactive way.
MIT License
1.28k stars 56 forks source link

A bit of guidance #62

Closed qur2 closed 8 years ago

qur2 commented 8 years ago

Hi,

I'm using Freezer and I really like how it simple it gets, thanks for the good work! I'm writing a small plugin for router5 + freezer. What it does is just to sync the router state into the frozen state. It's easy to do and there are at least 2 approaches:

  1. The plugin (which basically is a set of callbacks for router5), .set() directly in the store.
  2. The plugin uses a listener + trigger + reactions.

Knowing that:

  1. Is simpler and very straightforward
  2. Is more convoluted but works nicely with the redux devtools, since the trigger calls appear with the new state.

What would you recommend?

arqex commented 8 years ago

Hi @qur2 I am always keen to use reactions. I guess that url changes will update freezer's state, and to update the url you can use actions like:

freezer.trigger('url:go', '/my_path');
freezer.trigger('url:replace', '/my_path');

Inside those actions you can put all the router5 code, and other devs could hook directly into the action to detect url changes.

qur2 commented 8 years ago

Thanks for your insight. Also, in redux-router5, they allow to dispatch navigate actions to actually control the router. I'm wondering if that's a good idea for freezer or if I should keep it simple.

By the way: https://www.npmjs.com/package/freezer-js-router5

qur2 commented 8 years ago

Regarding triggering, does it make any difference to trigger on the state or from a listener (I assume so)? If so, what would be a a best practice? I assume that triggering on the state makes it easier for the client code since they don't have to get a listener from a node and they be interested only in the events and not the state itself. Does that make sense?

Thanks for your help.

qur2 commented 8 years ago

I'm closing this, thanks for your help. I've updated the lib to have reactions as well, but it is opt-in.