@wranggle/storage-local-forage-adapter
v0.2.4
Published
Use LocalForage as underlying store for WranggleStorage feature layers
Downloads
11
Maintainers
Readme
LocalForageAdapter
The LocalForageAdapter lets WranggleStorage use LocalForage as its underlying persistent store.
The LocalForage library itself is not bundled in with this adapter. The instructions below assume you've already installed it.
Constructing WranggleStorage with LocalForage
You can apply this adapter using the localForage
shortcut when constructing your WranggleStorage instance. Eg:
const store = new WranggleStorage({ localForage });
Or if localForage is available on window/global and you are ok with its defaults, you can use its minimal setup:
const store = new WranggleStorage({ localForage: true });
If you want to change the LocalForage configuration (eg, forcing a specific driver / storage location) pass WranggleStorage the already-configured LocalForage instance you want. Eg:
const lf = localforage.createInstance({ driver: localforage.WEBSQL }); // or localforage.config(opts)
const store = new WranggleStorage({ localForage: lf });
Installing From Individual Packages
For a web page, it is easiest to use the @wranggle/storage-web bundle.
Or you can add/install individual packages:
Add the @wranggle/storage-core and @wranggle/storage-local-forage-adapter packages to your project:
# From the command line using yarn: yarn add @wranggle/storage-core @wranggle/storage-local-forage-adapter # or with npm: npm install @wranggle/storage-core @wranggle/storage-local-forage-adapter
In your JavaScript, import or require the packages:
import WranggleStorage from '@wranggle/storage-core'; import LocalForageAdapter from '@wranggle/storage-local-forage-adapter' // or: const WranggleStorage = require('@wranggle/storage-core'); const LocalForageAdapter = require('@wranggle/storage-local-forage-adapter')
Instantiate your store:
const store = new WranggleStorage({ localForage });
Or do so without the construction shortcut:
const store = new WranggleStorage({ persist: new LocalForageAdapter({ localForage }));