mobx-persist-store-idb-adapter
v1.2.0-alpha
Published
IndexedDB adapter for mobx-persist-store
Downloads
144
Maintainers
Readme
IndexedDB adapter for mobx-persist-store
Provides an IndexedDB adapter for the mobx-persist-store library.
Installation
Yarn:
yarn add mobx-persist-store-idb-adapterNPM:
npm install mobx-persist-store-idb-adapterUsage 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 isfalse
Meta
stas35r – [email protected]
Distributed under the MIT license. See LICENSE for more information.
