Reactjs 如何结合RxDB和MobX
我从electron+react+mobx设置开始,现在想将RxDB添加到混合中。我以为我可以在商店里处理rxdb的东西(插入/订阅),但我真的不知道怎么做 基本上,我的问题是: 我如何同步我的Mobx存储和我的RxDB 目前的代码大致如下:Reactjs 如何结合RxDB和MobX,reactjs,electron,mobx,Reactjs,Electron,Mobx,我从electron+react+mobx设置开始,现在想将RxDB添加到混合中。我以为我可以在商店里处理rxdb的东西(插入/订阅),但我真的不知道怎么做 基本上,我的问题是: 我如何同步我的Mobx存储和我的RxDB 目前的代码大致如下: class RecordingStore { ... constructor() { database.getDatabase( 'mydb', 'idb').then(async(db) => {
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
}
据我推断,rxdb只是一个rxjs可观察的PockDB实例 如果您使用的是Mobx,那么您可以安全地跳过rxjs步骤,直接使用pockdb;否则,以简单的方式编写代码,并使用依赖项和..:
save() {
if (super.save()) {
POUCH_DB_INSTANCE.put(this.toJS());
}
}