Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a Storage implementation to be passed into the LocalStorage adapter #195

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cusspvz
Copy link

@cusspvz cusspvz commented Aug 30, 2023

The current implementation of the LocalStorage adapter relied directly on the browsers window.localStorage. These changes maintain the current behavior and allow devs to initialize the LocalStorage with a different Storage interface. I've defined the Storage interface to allow synchronous or asynchronous methods.

This change also allows LokiDB to persist information on platforms that don't offer indexedDB or FS. This is the case for React Native, or other implementations that don't support IndexedDB, by allowing devs to provide a storage interface, React Native's Async Storage can now be fed to LokiDB as a persistent storage mean.

Also took the chance that I had to edit the tests to ensure other implementations could fit into those interfaces, so I've introduced 2 mocked-storages, async and sync, to ensure the intended behavior works as expected. As the tests were not using the async/await feature, ended up rewriting those.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant