support createInstance
Goldziher opened this issue ยท 7 comments
Hi there!
Thanks a lot for this package - its really nifty. In fact I am using it as a dependency in a cache wrapper im working on :). I haven't tested this in live code, but writing jest tests for my package, I noticed something peculiar-
const AsyncStorageDriver = driverWithDefaultSerialization()
await localforage.defineDriver(AsyncStorageDriver)
await localforage.setDriver(AsyncStorageDriver._driver)
//@ts-ignore
console.log(localforage._driver) // "rnAsyncStorageWrapper-withDefaultSerializer"
const instance = localforage.createInstance()
//@ts-ignore
console.log(localforage._config._driver) // "localStorageWrapper"
Does this package support instances?
Hmm. or Im an idiot. Closing this issue...
Okay, no problem. If you still perceive some issues, let me know.
well, i will suggest adding a paragraph in the docs for making sure to also do this:
const instance.createInstance({ driver: AsyncStorageDriver._driver })
Otherwise the driver is not passed from localForage. I'd assume this is a very "hidden feature" or simply broken localForage functionality ๐
Ah I see. I always did somehow the following as in the LF-docs:
const instance = localforage.createInstance({ name: 'mySecretInstanceName }); // because I required multiple instances with different names ...
instance.defineDriver(AsyncStorageDriver._driver);
๐
I will somehow add it and suggest both solutions...
The documentation misses saying this step which is essential.
instance.defineDriver(AsyncStorageDriver._driver);
instance.defineDriver(AsyncStorageDriver._driver);
it's worth noting this returns a promise, so you will likely need to do await instance.defineDriver(AsyncStorageDriver._driver);
, depending how your code is arranged