mobx-utils
mobx-utils copied to clipboard
keepAlive can be deprecated
MobX 4.1 introduced keepAlive as option to computed
I've got just little utility I use which relies on keepAlive as-is:
function onBecomeObservedKeepAlive(target: object, property: string) {
onBecomeObserved(target, property, () => keepAlive(target, property));
}
This is only there to work around the behaviour of keepAlive evaluating the computed that it is keeping alive, but I don't think I'd be able to do this without keepAlive in its current form (well, apart from maybe misusing a reaction)
@jamiewinder What's the use-case for your onBecomeObservedKeepAlive utility?
@NaridaL - at the time, the behaviour of keep alive was such that applying it meant the computed would be resolved immediately as if something was always observing it. In fact, that's how it worked as I recall.
The utility made it so that the computed was only resolved when first observed, as with a normal computed property.
we would love to be able to keep keepAlive as a utility. Yes we can do computed({ keepAlive: true }) but there's no way to turn keepAlive off after that. And we're scared of memory leaks so we would like to be able to turn it off after our heavy computation step.