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

need AsyncLocalStorage (was #904) #906

Closed
Jxck opened this Issue May 31, 2016 · 4 comments

Comments

Projects
None yet
4 participants
@Jxck
Copy link

Jxck commented May 31, 2016

localStorage is handy for much usecases, but unfortunately it's api based on Sync.
so in service worker we need to use Indexed DB for every kind of data, only if you need to store 1byte flag.

I think if we don't need index for large data search, and don't wanna preparing ceremony for storing data,
it's better to have a localStorage witch having Async API.

or other sight of view, Cache API is much handy than IDB, but it's specialised for Request/Response.
AsyncLocalStorage will looks something like CacheAPI witch is generalised for generic javascript object.
(we may say it as parent class of Cache API class)

this will solve may use case I think, for example..

  • every use case for localStorage at window context
  • saving request data for sync event (I described it at #904)
  • saving simple/single/small data like flag, counter etc
  • case for preparing scheme at install/activate are over kill

will seems..

localStorage with AsyncAPI (returning promise)

asyncStorage.setItem('key', 'value').then();
asyncStorage.getItem('key').then(console.log.bind(console)); // 'value'
// etc

generalised cache api

asyncStorage.open('v-1').then((store) => {
  store.put('key', {data:'value'}).then();
  store.match('key').then(console.log.bind(cosnole)); // { data: 'value' }
  // etc but, no add/addAll
});
@delapuente

This comment has been minimized.

Copy link

delapuente commented Jun 6, 2016

@Jxck despite the proposal for adding an async API to localStorage is good and IDB API sucks, you can use localForage.

@jakearchibald

This comment has been minimized.

Copy link
Collaborator

jakearchibald commented Jun 6, 2016

This isn't the right repo for this, but it might be worth proposing at the WICG.

In the mean time, little libs like https://github.com/jakearchibald/indexeddb-promised make IDB a lot easier. Includes async localstorage example.

@domenic

This comment has been minimized.

Copy link
Contributor

domenic commented Apr 11, 2018

FWIW, I've got a proposal for this that I think is pretty complete: https://domenic.github.io/async-local-storage/. Feel free to file issues on the tracker there, or chime in on existing discussions!

@Jxck

This comment has been minimized.

Copy link

Jxck commented Apr 12, 2018

@domenic 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment