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

MobX 6: Memory leak in hydrate()

Open RusovVladimir opened this issue 4 years ago • 1 comments

I want to use hydrate() many times with short live mobx-store objects. Therefor I want to clear any watchers. But there is a reaction into hydrate() function and I can't call dispatch function of this reaction. hydrate source code:

// mobx-persist/src/index.ts
export function create({
    storage = Storage as any,
    jsonify = true,
    debounce = 0
}: any = {}) {
    return function hydrate<T extends Object>(key: string, store: T, initialState: any = {}, customArgs: any = {}): IHydrateResult<T> {
// ...
        const result = hydration()
        reaction(
            () => serialize(schema, store),
            (data: any) => storage.setItem(key, !jsonify ? data : JSON.stringify(data)),
            {
                delay: debounce
            }
        )
        return result

In MobX@6 reaction function returns dispose function. MobX docs says Always dispose of reactions.

RusovVladimir avatar Nov 20 '20 10:11 RusovVladimir

hi did you manage to get the persist work with mobx 6? @RusovVladimir

morelgarisi avatar Jun 17 '21 13:06 morelgarisi