Skip to content

Commit

Permalink
refactor: Storage createInstance uses default options.
Browse files Browse the repository at this point in the history
  • Loading branch information
darkobits committed Jun 7, 2024
1 parent 92511b0 commit e30a30c
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/web/lib/storage.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import localforage from 'localforage';
import LocalForage from 'localforage';

type LocalForageOptions = Parameters<typeof LocalForage['createInstance']>[0];

const storage = localforage.createInstance({
driver: localforage.LOCALSTORAGE,
const defaultOptions: LocalForageOptions = {
driver: LocalForage.LOCALSTORAGE,
name: 'inspirat',
version: 1,
description: 'Inspirat'
});
};

const storage = LocalForage.createInstance(defaultOptions);

const originalCreateInstance = storage.createInstance.bind(storage);

storage.createInstance = (options: LocalForageOptions) => {
return Reflect.apply(originalCreateInstance, storage, [{
...defaultOptions,
...options
}]);
};

export default storage;

0 comments on commit e30a30c

Please sign in to comment.