This is like a follow up on some older post:
https://groups.google.com/forum/#!topic/clientside/G9G1pmup5dU
I'm now using storage more throughout a site. Storage is a wrapper/helper class for localStorage for storing in a namespace and first-in-first-out stuff.
I pass it to Behavior and Delegator using passMethod(s) (getStorage: Function.from(storage)). This worked fine for storing stuff etc.
Right now I have to update multiple tabs or windows open with the same site/page from what is inside the localStorage whenever some keys are changed.
For this I use the storage event that is fired from localStorage (exposed through my Storage class as a change event).
When doing some dirty tests I was doing it like this:
Behavior.addGlobalFilter('Foo', function(element, api){
var foo = new Foo(element, {});
var storage = api.getStorage();
if (storage){ //false if there's no localStorage
var updateFooFromStorage(event){
.... //compare event.event.key, do something with a newValue, or not... etc.
}
storage.addEvent('change', updateFooFromStorage);
api.onCleanup(function(){ storage.removeEvent('change', updateFooFromStorage);
}
return foo;
});
Does this make sense or should I do things differently? It feels a bit strange because I'm adding multiple 'change' event listeners, the compare the changed key with a element-specific-storage-key declared on the element (to which the behavior filter is applied).
Or is it just me using Behavior for stuff I shouldn't ;)