Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MobX 6: Memory leak in hydrate() #90

Open
RusovVladimir opened this issue Nov 20, 2020 · 1 comment
Open

MobX 6: Memory leak in hydrate() #90

RusovVladimir opened this issue Nov 20, 2020 · 1 comment

Comments

@RusovVladimir
Copy link

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.

@morelgarisi
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants