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

sculk

v1.1.1

Published

A small set of utility functions for creating an action-based pattern

Downloads

1

Readme

sculk

A small set of type-safe utility functions to create a flux-like implementation for your applications. Separate logic from the UI by passing actions to dispatch() whilst your flows handle all the logical stuff, skulk isn't a state management solution, but works in conjunction with some of them.

Quick Start

If you've used redux middleware before, it's basically just that in a more smaller scale.

const flow1 = (action, next, dispatch) => {
  console.log(1);
  return next(action);
};
const flow2 = (action, next) => {
  console.log(2);
  return next(action);
};

const dispatch = createChain(flow1, flow2);
dispatch({
  /*...*/
}); // logs 1 and 2!

You can also wrap chains inside chains to better organize your flows:

const chain1 = createChain(flow1, flow2);
const chain2 = createChain(chain1, flow3, flow4);
const dispatch = createChain(chain2, flow5);
// order --> flow1 flow2 flow3 flow4 flow5

Note that you must not re-use chains or call them before passing them into createChain! This is because memoization happens under the hood on the first call, which then locks them from being reused.

// depending on which dispatch gets called first, chain1 will always point next to either chain2 or chain3 no matter which dispatch function you will use.
const dispatch = createChain(chain1, chain2);
const anotherDispatch = createChain(chain1, chain3);


const chain1 = createChain(flow1, flow2);
chain1({
  /*...*/
});
const chain2 = createChain(chain1, flow3, flow4); // will not work as expected!

Creating Actions

we also have a watered-down version of createAction from redux toolkit, without the thunks.

const increment = createAction<number>('increment');
const decrement = createAction<string>('decrement');
const action = increment(1);

// match the actions:
console.log(increment.match(action)) // true
console.log(decrement.match(action)) // false

Creating Sculks

I found it tedious to create an action and a flow that only responds to said action, as well as having to check if that action is said action, so why not combine them together?

Sculks act as action creators if called and act like flows if passed to createChain.

const increment = createSculk<number>("increment", (action, next) => {
  // actions are already checked under the hood, no need to match them.
  console.log(action.type) // "increment"
  return next(action);
});

increment(1); // { type: "increment", payload: 1 };
const dispatch = createChain(increment); // will instead use the second arg from createSculk