Giter VIP home page Giter VIP logo

Comments (14)

acrazing avatar acrazing commented on September 27, 2024

Yes, I found it updated at: https://github.com/mobxjs/mobx/blob/master/src/api/autorun.ts#L19

from mobx-sync.

acrazing avatar acrazing commented on September 27, 2024

I will update it at tomorrow

from mobx-sync.

georgiosd avatar georgiosd commented on September 27, 2024

Thanks!

from mobx-sync.

acrazing avatar acrazing commented on September 27, 2024

updated mobx to version 4.x

from mobx-sync.

georgiosd avatar georgiosd commented on September 27, 2024

Hm, I think it doesn't work. Notice this from the docs:

Just like the @observer decorator/function, autorun will only observe data that is used during the execution of the provided function.

from mobx-sync.

acrazing avatar acrazing commented on September 27, 2024

Well, I'm not sure what the problem is, and the test case about autorun is passed, see the code: https://github.com/acrazing/mobx-sync/blob/master/src/async.spec.ts#L136, the run result about it is:

next
    ✓ init
storage.get key: undefined
storage.set key: {"node":{"hello":"world"}}
storage.set key: {"node":{"hello":"world"}}
storage.set key: {"node":{"hello":"John"}}
storage.get key: {"node":{"hello":"John"}}
    ✓ should autorun

But, I found the @ignore is not working with @observable now, I think it is something wrong with mobx, but I cannot fix it now, for I have no time to read the source code of mobx. You can see it at https://github.com/acrazing/mobx-sync/blob/master/src/ignore.spec.ts.

from mobx-sync.

acrazing avatar acrazing commented on September 27, 2024

I have added an issue for mobx at mobxjs/mobx#1493, you can subscribe it to find something maybe useful.

from mobx-sync.

georgiosd avatar georgiosd commented on September 27, 2024

In my tests, to make it work again, I had to access all the fields inside autorun:

class UserStore {
    @observable user;

    constructor() {
        const trunk = new SyncTrunk(this);
        
        trunk.init();

        autorun(() => {
            trunk.persist(JSON.stringify({ user: this.user }));
        })
    }
}

The parameter to persist is obviously is ignored but prevents webpack from optimizing it away.

from mobx-sync.

acrazing avatar acrazing commented on September 27, 2024

You must init user field before init trunk, for JSON.stringify need to access properties to invoke mobx observer. For example: you can change like this:

class UserStore {
  @observable user: any = null
  constructor() {
    const trunk = new SyncTrunk(this)
    trunk.init()
  }
}

from mobx-sync.

georgiosd avatar georgiosd commented on September 27, 2024

Hm, I tried that (in babel JS, not TS) and it didn't work either.

from mobx-sync.

acrazing avatar acrazing commented on September 27, 2024

Maybe something is wrong, could you paste your code here (fully)?

from mobx-sync.

dehypnosis avatar dehypnosis commented on September 27, 2024

here same issue..

from mobx-sync.

acrazing avatar acrazing commented on September 27, 2024

@dehypnosis Could you paste your code here?

from mobx-sync.

dehypnosis avatar dehypnosis commented on September 27, 2024

Thanks for fast response..

import { observable, autorun, computed, toJS } from "mobx";
import { AsyncTrunk, version, ignore } from "mobx-sync";

class Store {
  @observable test: string = "hello";
}

const store = new Store();
const trunk = new AsyncTrunk(store, { storage: localStorage, storageKey: "gateway-admin-webapp" });

trunk.init().then(() => {
  // @ts-ignore
  window.store = store;
})

window.store = store statement is for debugging. After browser (chrome) loaded, store.test = "goodbye" invokes no local storage update. There made an empty object {}.
But when code changed a little:

console.log(store.test);
trunk.init().then(() => {
  // @ts-ignore
  window.store = store;
})

local storage sync works like a charm.
I thinks that It may related to lazy initialization.. thing?
And after local storage has been updated at once, so after { test : "any" } has been stored, even without above code which make an access to store property, local storage sync works well.

trunk.init().then(() => {
  // @ts-ignore
  window.store = store;
})

the bug is about initialization..... thanks

from mobx-sync.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.