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

setItem should return the dispatch promise #438

Open
BraunreutherA opened this issue May 23, 2024 · 0 comments
Open

setItem should return the dispatch promise #438

BraunreutherA opened this issue May 23, 2024 · 0 comments

Comments

@BraunreutherA
Copy link

Hey there 👋

Currently there's no way to know, when a item was set to a storage (except for adding a listener, but this doesn't work for a control flow).

const myPlugin = {
  initialize: ({ instance }) => {
    instance.setItem('foo', 'bar');

    const foo = instance.getItem('foo');
    
    console.log(foo); // => undefined
  }
}

This happens, because internally instance.setItem fires a dispatch, which is basically async. The type of it is actually sync which leads to the getting the item directly afterwards being undefined.
instance.setItem here should be changed to return the dispatch promise, so it can get awaited.

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

No branches or pull requests

1 participant