Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何结合RxDB和MobX_Reactjs_Electron_Mobx - Fatal编程技术网

Reactjs 如何结合RxDB和MobX

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) => {

我从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
  }

据我推断,rxdb只是一个rxjs可观察的PockDB实例

如果您使用的是Mobx,那么您可以安全地跳过rxjs步骤,直接使用pockdb;否则,以简单的方式编写代码,并使用依赖项和..:

save() {
    if (super.save()) {
        POUCH_DB_INSTANCE.put(this.toJS());
    }
}