【发布时间】:2018-12-17 21:05:33
【问题描述】:
我开始使用 electron + react + mobx 设置,现在想将 RxDB 添加到组合中。我以为我可以在商店内处理 rxdb 的东西(插入/订阅),但我真的不知道怎么做。
基本上我的问题是:
如何同步我的 Mobx 商店和我的 RxDB?
目前的代码大致是这样的:
class RecordingStore {
...
constructor() {
database.getDatabase( 'mydb', 'idb').then(async(db) => {
this.db = db
await db.recordings.sync({
remote: syncURL,
direction: {
pull: true,
push: true
}
});
}
}
@action addRecording(title) {
const item = new Recording(title)
// should I really keep two collections? (RxDb AND Mobx)
this.recordings.push(item)
this.db.recordings.insert({ title: title }).then(()=>{console.log("recording saved")})
return item
}
【问题讨论】: