mobx-utils icon indicating copy to clipboard operation
mobx-utils copied to clipboard

keepAlive can be deprecated

Open mweststrate opened this issue 7 years ago • 4 comments

MobX 4.1 introduced keepAlive as option to computed

mweststrate avatar Mar 15 '18 16:03 mweststrate

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 avatar May 25 '18 13:05 jamiewinder

@jamiewinder What's the use-case for your onBecomeObservedKeepAlive utility?

NaridaL avatar May 24 '20 11:05 NaridaL

@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.

jamiewinder avatar May 24 '20 17:05 jamiewinder

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.

akphi avatar Apr 06 '22 21:04 akphi