IndexedDB adapter for mobx-persist-store
Adapter for storing data using mobx-persist-store
Provides an IndexedDB adapter for the mobx-persist-store library.
Installation
Yarn:
yarn add mobx-persist-store-idb-adapter
NPM:
npm install mobx-persist-store-idb-adapter
Usage example
import { makeAutoObservable } from "mobx";
import { makePersistable } from "mobx-persist-store";
import DBController from "mobx-persist-store-idb-adapter";
class StoreExample {
counter = 0;
constructor() {
const indexedDBStore = new DBController("dbName", "objectStoreName", 1);
makeAutoObservable(this, {}, { autoBind: true });
makePersistable(this, {
name: "StoreExample",
properties: ["counter"],
storage: indexedDBStore,
stringify: false,
});
}
increase() {
this.counter += 1;
}
decrease() {
this.counter -= 1;
}
}
export const storeExample = new StoreExample();
Configuration
const indexedDBStore = new DBController("dbName", "objectStoreName", 1);
indexedDBStore.config({ downgrading: true });
Options
downgrading
- when opening a database with a version lower than the existing one, the database will be dropped and re-create with a lower version, default is false
Meta
stas35r – stas35r@gmail.com
Distributed under the MIT license. See LICENSE for more information.
https://github.com/stas35r/mobx-persist-store-idb-adapter