npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

storeon-until

v1.1.0

Published

Small simple utility for awaiting [Storeon] event occurs

Downloads

14,384

Readme

storeon-until

npm version Build Status Coverage Status

Utility for awaiting Storeon events.

It size is 67 B (minified and gzipped) and uses Size Limit to control size.

Overview

The goal of this tiny library is provide the easy way to awaiting occurrence of the particular storeon event.

Install

npm i storeon-until --save

Usage

Simple usage

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);

More verbose usage


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.

Api

  • until - is function which returns UntilResult (which is promise) of requested event data. Params:
    • store the store
    • event the event which we are waiting for
    • condition - (optional) - the function which gets state, and event data and have to return true if promise has to be resolved for that state or data
  • UntilResult
    • dispatchOver - function which allows to dispatch event on the store in await place