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

Datastore - Support IndexedDBAdapter for WebWorker #6870

Closed
tlikits opened this issue Sep 25, 2020 · 2 comments
Closed

Datastore - Support IndexedDBAdapter for WebWorker #6870

tlikits opened this issue Sep 25, 2020 · 2 comments
Labels
DataStore Related to DataStore category feature-request Request a new feature

Comments

@tlikits
Copy link
Contributor

tlikits commented Sep 25, 2020

Is your feature request related to a problem? Please describe.
We have a project plan that to use the Datastore with the WebWorker, and store the synced data into the local IndexedDB.
But the current behavior is it will pick the AsyncStorageAdapter instead of IndexedDBAdapter. As it only allow to use IndexedDBAdapter when browserOrNode().isBrowser is true.

Describe the solution you'd like
Currently, required('@aws-amplify/core').browserOrNode().isBrowser is return as false when we use the WebWorker, as this flag is check by typeof window !== 'undefined' && typeof window.document !== 'undefined', which the window will always be, by default, undefined in WebWorker.

So I suggest providing isWebWorker flag in the JS, with the following logic:
typeof self !== 'undefined' && self.constructor.name === 'DedicatedWorkerGlobalScope';

And update the getDefaultAdapter, to check (isBrowser && window.indexedDB) && (isWebWorker && self.indexedDB).

Describe alternatives you've considered
-

Additional context
-

@tlikits tlikits added the feature-request Request a new feature label Sep 25, 2020
@manueliglesias manueliglesias added the DataStore Related to DataStore category label Sep 25, 2020
@iartemiev
Copy link
Member

Thank you for opening the PR, @wylfent. It was released as part of aws-amplify@unstable and will be included in the next stable release this week.

@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
DataStore Related to DataStore category feature-request Request a new feature
Projects
None yet
Development

No branches or pull requests

3 participants