Comments (2)
You can use custom formatter to stringify/parse your set of Options
. For example:
import { format, parseStore } from 'mobx-sync';
class ProfileStore {
@format(
(data: Array<Pick<Option, 'label' | 'value'>>) =>
new Set(data.map((item) => new Option(item))),
(value: Set<Option>) => Array.from(value),
)
options = new Set<Option>();
}
class Option {
label: string;
value: string;
constructor(config: Pick<Option, 'label' | 'value'>) {
this.label = config.label;
this.value = config.value;
}
someAction() {
return 'hello world';
}
}
const profile = new ProfileStore();
profile.options.add(new Option({ label: 'label', value: 'value' }));
const stateValue = JSON.stringify(profile);
console.log(stateValue);
const newProfile = new ProfileStore();
parseStore(newProfile, JSON.parse(stateValue), false);
console.log(
newProfile.options.size,
newProfile.options
.values()
.next()
.value!.someAction(),
);
The upon code will output the following stdout:
{"options":[{"label":"label","value":"value"}]}
1 'hello world'
from mobx-sync.
Oh man, I feel silly, I hadn't seen that in the docs when I'd just been in there around the async vs. sync behavior. I'd been bouncing between Mobx and sync docs. Thanks! My knowledge of OO as it is applied (and re-applied) in JavaScript is unreliable at best. I don't recognize them when they slap me in the face. :)
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
- 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.