Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
storeon-until
Advanced tools
Changelog
1.1.0
Readme
Utility for awaiting Storeon events.
It size is 67 B (minified and gzipped) and uses Size Limit to control size.
The goal of this tiny library is provide the easy way to awaiting occurrence of the particular storeon event.
npm i storeon-until --save
From version 1.1.0 we provided the shortcut to inline the await statement with dispatch.
The returned promise contains the dispatch
function which allows to dispatch the event on store,
that function returns the promise again.
import { createStoreon } from "storeon";
import { until } from "storeon-until";
// create store
const store = createStoreon([]);
// some async event handler
store.on('loadDocument', async (state, id) => {
const document = await fetch(`http://some.document.com/${id}`);
store.dispatch('documentLoaded', {id, document});
});
// reducer for ending event
store.on('documentLoaded', (_, {id, document}) => ({
id,
document
}));
const {id, document} =
// awaiting for the ending event
await until(store, 'documentLoaded', (_, {id}) => id === 'id1')
// dispatch event over waiting
.dispatchOver('loadDocument', 'id1');
console.log(document);
const {id, document} =
// waits until data in state will pass condition
await until(store, '@changed', ({id}) => id === 'id2')
// dispatch event over waiting
.dispatchOver('loadDocument', 'id2');
console.log(document);
import { createStoreon } from "storeon";
import { until } from "storeon-until";
// create store
const store = createStoreon([]);
// some async event handler
store.on('loadDocument', async (state, id) => {
const document = await fetch(`http://some.document.com/${id}`);
store.dispatch('documentLoaded', {id, document});
});
// reducer for ending event
store.on('documentLoaded', (_, {id, document}) => ({
id,
document
}));
// awaiting for the ending event
const documentLoadedPromise = until(store, 'documentLoaded', (_, {id}) => id === 'id1');
// dispatch event
store.dispatch('loadDocument', 'id1');
// waits until async flow will finish
const {id, document} = await documentLoadedPromise;
console.log(document);
// we can also await for the state
const statePromise = until(store, '@changed', ({id}) => id === 'id2');
// dispatch event
store.dispatch('loadDocument', 'id2');
// waits until data in state will pass condition
const {id, document} = await statePromise;
console.log(document);
Caution
Please notice, that we should always use until
utility to create promise before the event dispatch
as dispatched event can run synchronously.
until
- is function which returns UntilResult
(which is promise) of requested event data. Params:
store
the storeevent
the event which we are waiting forcondition
- (optional) - the function which gets state, and event data and have to return true
if promise has to be resolved for that state or dataUntilResult
dispatchOver
- function which allows to dispatch event on the store in await placeFAQs
Small simple utility for awaiting [Storeon] event occurs
The npm package storeon-until receives a total of 2,940 weekly downloads. As such, storeon-until popularity was classified as popular.
We found that storeon-until demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.