【发布时间】:2018-09-13 05:50:21
【问题描述】:
我有一个使用 MobX 的 React Native 应用程序。我的商店有一个默认对象,当用户使用操作(在 Options.js 文件中)更新值时,我想将其保存在本地(React Native 的 AsyncStorage),以便下次打开应用程序时对象未重置为默认值。在首次运行、检查和加载新值时处理这个问题的好模式是什么?
我的 RootStore.js 看起来像这样:
import { observable, action } from 'mobx';
export default class RootStore {
constructor() {
this.sources = new Sources(this);
}
}
class Sources {
constructor(rootStore) {
this.rootStore = rootStore;
}
@observable
left = [
{
active: 'yes',
side: 'value One',
name: 'value Two',
},
];
//passing in new object from Options.js
@action
updateActiveLeft(data) {
let object = data;
this.left = object;
console.log('New active name set in store - ' + this.left[0].name);
}
【问题讨论】:
标签: javascript react-native mobx