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

@storasy/core

v0.2.3

Published

<p> <a aria-label="NPM version" href="https://www.npmjs.com/package/@storasy/core"> <img alt="" src="https://badgen.net/npm/v/@storasy/core"> </a> <a aria-label="Package size" href="https://bundlephobia.com/result?p=@storasy/core">

Downloads

4

Readme

Storasy

Storasy Header library for working with asynchronous data

Quick Start

NodeJS

Inside your project directory, run in terminal:

yarn add @storasy/core

Or with npm:

npm install @storasy/core

Browser

...
<body>
...
<script src="https://unpkg.com/@storasy/core/dist/umd/storasy.production.js"></script>
<script>
  const storasy = window.storasy;
  ...
</script>
...
</body>

API

StorasyClient

import { createStorasyClient } from './create-storasy-client';

//options - optional
const storasyClient = createStorasyClient({
  abortController: {
    createAbortController: () => new AbortController(),
    getSignal: controller => controller.signal,
    abort: controller => controller.abort(),
    checkOnError: error => error.name === 'AbortError'
  }
});
Accept:
- abortController

Optional, creates an AbortController by default. Allows you to cancel asynchronous requests.

Axios Example:

const abortController = {
  createAbortController: () => axios.CancelToken.source(),
  getSignal: (token: CancelTokenSource) => token.token,
  abort: (token: CancelTokenSource) => token.cancel(),
  checkOnError: error => axios.isCancel(error)
}
Return:
- get

Getter for storasy item

const item = storasyClient.get('key');
- create

Creation storasy item.

//initialState - optional
storasyClient.create('key', initialState = 1)
- include

Checking for the presence of an item in the store.

storasyClient.include('key')
- put

Changing an existing item in the store.

storasyClient.put('key', 'newState');

// or with callback

storasyClient.put('key', oldState => 'newState');
- delete

Secure deletion of an item if there are no subscribers. Return a Boolean value.

const isDelete = storasyClient.delete('key');

console.log(isDelete);
- run

Starting the generator within the storasy item

function* generator(params) {}

const { refetch, cancel } = storasyClient.run('key', generator, {
    enabled: true, // If true, the generator will start immediately 
    params // Parameters that will get into the generator
});

// newParams - optional. Otherwise, the old ones get caught
refetch(newParams)
- subscribe

Subscription to change the state of the item

const state = null;

const unsubscribe = storasyClient.subscribe('key', item => state = item.state);

StorasyItem

const item = storasyClient.get('key');
- subscribersLength

Get the number of subscribers from the item

const subsLength = storasyClient.get('key').subscribersLength;
- getItem

Getter for state of the item

const item = storasyClient.get('key').getItem();

type TStorasyItem<T> = {
  state?: T;
  status: TStorasyItemStatus;
  error?: string;
  isLoaded: boolean;
  isLoading: boolean;
  isError: boolean;
  isStale: boolean;
};
- getState

Getter for item data

const data = storasyClient.get('key').getState();
- putState

Setter for item data

const item = storasyClient.get('key');

item.put('newData');

// or with callback

item.put(oldData => 'newData');
- putStatus

Set new item status

const item = storasyClient.get('key');
const newStatus = 'loading' | 'loaded';

item.putStatus(newStatus);
- putItem

Setter for item

const item = storasyClient.get('key');

item.putStatus(
    newState, //  newState | (oldState) => newState
    newStatus, // 'loading' | 'loaded'
    error, // string | undefined
);
- subscribe

Subscribe to item change

const item = storasyClient.get('key');
const state = null;

const unsubscribe = item.subscribe(itemState => state = itemState.state);
- getAbortController

Get the controller to cancel the request

const item = storasyClient.get('key');

const ac = item.getAbortController();

Examples

License

The MIT License.