Closed christophe-g closed 3 years ago
Closing as appState.addObserver((name) => if(name === 'language') {doSthm})
covers this use case much better !
yes, and you can actually also observe a specific stateVar, so you don't have to do the if (name === 'language')
:
appState.addObserver(myObserver, ['language']);
And yes, you can also create a custom stateVar Handler that does something specific when a state changes. However, you don't need the method decorating feature for that. You just need to override the get
and/or set
of the stateVar handler.
You only need to decorate a method when you need access to the this
reference or your state class. For callbacks for example.
appState.addObserver(myObserver, ['language']);
Ah, great, thank you ! and thanks for this lib, really. C.
Hey - thanks a lot for this new release. I have been playing with it today, and looks like a great opportunity to drop Redux boilerplate from my app.
I am having some difficulties to make the following use case (from the docs, below) work.
The goal is to have a customizable way to do smth when a state var updates (example: update document
lang
anddir
attribute whenlanguage
var updates). From what I get from the docs, it seems providing options from a method is supposed to tackle such cases.Also, what would be the advantages (other than proper scoping the callback) over smth like (with a handled calling the
callback
function on update) :