Rich-Harris / Statesman

The JavaScript state management library

Home Page:https://github.com/Rich-Harris/Statesman/wiki

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

state.unobserve(keypath)

Mparaiso opened this issue · comments

Hi , thanks for the library.

How about state.unobserve(keypath), where keypath is a string. it should remove listeners for any keypath that matches.

for instance :

s.observe("video[0].title",aFunction);
s.observe("video[0].title",anotherFunction);
// 
s.unobserve("videos[0].title");
// remove the 2 previous listeners.

Yeah, this makes sense. Have also added an unobserveAll method as well. By the way, you might not have picked it up from the crappy documentation (will get round to updating it one day!) but you can also cancel observers like this:

observer = state.observe( 'foo' );
observer.cancel();

Thanks for the suggestion