DavidWells / analytics

Lightweight analytics abstraction layer for tracking page views, custom events, & identifying visitors

Home Page:https://getanalytics.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

setItem should return the dispatch promise

BraunreutherA opened this issue Β· comments

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.