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

We have to check docs #23

Open kuraga opened 9 years ago

kuraga commented 9 years ago

We have to check if every API method is mentioned in docs.

Tjorriemorrie commented 7 years ago

Is emit still valid? TypeError: freezer.emit is not a function

arqex commented 7 years ago

Hey @Tjorriemorrie

emit is now the way of trigger events. trigger is deprecated. If you are seeing that message is either because you are using an old version of freezer, or you are not initalizating the store properly

This should work:

import Freezer from 'freezer-js';
var freezer = new Freezer({});
freezer.emit('my:event');
Tjorriemorrie commented 7 years ago

Thanks, I was stuck on 0.11 for some reason. This is such a great library.

arqex commented 7 years ago

I am glad you liked it :) I am preparing a little a article with freezer patterns to celebrate the 1000 stars, keep tuned!

arqex commented 7 years ago

In fact! Here it is the article draft. If you want to preview and share your thoughts I'll be so grateful: https://medium.com/@arqex/7-tips-using-react-with-freezer-f4d75e363b94

Tjorriemorrie commented 7 years ago

It's a good article. Maybe touch on how redux selectors are similarly handled. And also when freezer.on is added to the component, does it create a listener? Meaning do I have to unset the listener/something when the component unmounts (or only specifically when freezer's addListener was used)?

arqex commented 7 years ago

By selector you mean this? https://github.com/reactjs/reselect

It's great, I had never heard of them and I think it's possible to use them with freezer out of the box.

Good appreciation on stop listening events on components that are using freezer.on. In the article I suggest to only have one listener at the top component of your React tree. In my case that component is never unmounted so I will never need to stop listening. It's cool, one thing less I need to care about.