Created
September 20, 2016 13:56
-
-
Save leaysgur/55ef355827f2b045352b23c91e191d9e to your computer and use it in GitHub Desktop.
More better mobx way?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Model = require('Model'); | |
class Store { | |
constructor() { | |
extendObservable(this, { | |
items: asFlat([]), // wanna make this Array<Model> | |
}) | |
} | |
fooFunc(someData) { | |
this.items.push(new Model(someData)); // but I don't want to write `new` | |
} | |
barFunc(someDataArr) { | |
this.items.replace(someDataArr.map((data) => { return new Model(data); })); // so many times.. | |
} | |
} |
Author
leaysgur
commented
Sep 20, 2016
- createTransformer is suitable for this case?
- or should use Intercept?
my workaround.
constructor() {
// ...
intercept(this.items, __toModelInterceptor);
function __toModelInterceptor(change) {
change.added = change.added.map((item) => {
return new Model(item);
});
return change;
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment