DavidWells / DavidWells/analytics

setItem should return the dispatch promise

Open
#438 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
2.7k
Forks
267
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at packages/analytics-core/src/index.js around line 778, where instance.setItem is defined and dispatch is triggered. Trace the dispatch call and its returned promise, then verify that awaiting setItem allows a subsequent getItem('foo') to observe the stored value. Done means the API returns the dispatch promise and its type reflects that asynchronous result.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.