Comments (14)
Yes, I found it updated at: https://github.com/mobxjs/mobx/blob/master/src/api/autorun.ts#L19
from mobx-sync.
I will update it at tomorrow
from mobx-sync.
Thanks!
from mobx-sync.
updated mobx to version 4.x
from mobx-sync.
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.
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.
I have added an issue for mobx at mobxjs/mobx#1493, you can subscribe it to find something maybe useful.
from mobx-sync.
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.
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.
Hm, I tried that (in babel JS, not TS) and it didn't work either.
from mobx-sync.
Maybe something is wrong, could you paste your code here (fully)?
from mobx-sync.
here same issue..
from mobx-sync.
@dehypnosis Could you paste your code here?
from mobx-sync.
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)
- no releases?
- api reference links broken HOT 1
- tons of import errors HOT 6
- mjs modules aren't compatible with react-create-app HOT 4
- Any way to handle persistence exceptions? HOT 2
- Failed to compile. Can't import the named export '__awaiter' from non EcmaScript module HOT 1
- Handling actions on classes. HOT 2
- Not working for arrays HOT 9
- Question: Which version control should I use? HOT 1
- ReactJs TypeScript - AsyncTrunk is not a constructor HOT 2
- Spelling Issue In Your Medium Article HOT 1
- Incredibly slow refresh times
- Computed property not working after hydration HOT 2
- Inverted behaviour HOT 3
- Can't get @ignore to work HOT 4
- Persist Multiple Stores?
- Example of how to use without decorators? HOT 1
- How the fallback works? And errors question HOT 4
- Using formatters with TS interface
- Project maintenance HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mobx-sync.