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

@nteract/myths

v0.2.13

Published

A redux-observable framework for better locality of dependencies

Downloads

8,009

Readme

myths (currently: @nteract/myths, TBC)

This is a pre-alpha level package; interfaces are not stable yet!

The myths framework allows for integrating sets of closely related actions, reducers and epics. Myths allow close relationships where DRY and dependencies are minimized. Therefore, Myths provide for a structured way to avoid boilerplate.

Myths build on top of the Redux and RxJS libraries that are used elsewhere in the nteract core SDK. As a refresher, Redux helps you maintain application state. In Redux, actions and reducers provide predictable state management. The state may only be changed by dispatching an action to a reducer. In Redux-Observable, an epic is a function that takes in a stream of actions and returns a stream of actions.

Installation

$ yarn add myths
$ npm install --save myths

Usage

MythicPackage

First, create a MythicPackage with a name, a type for its private state, and the initial state. As an example, the following creates a MythicPackage named "iCanAdd" which uses the number type for its private state sum and an initial state of sum as 0:

export const iCanAdd = createMythicPackage("iCanAdd")<
  {
    sum: number;
  }
>({
  initialState: {
    sum: 0,
  },
});

Myth

Next, you can the use the MythicPackage to create a Myth with a name, a type for its payload, and optionally a reducer operating on its package's private state. In this example, the MythicPackage named iCanAdd creates a Myth named "addToSum":

export const addToSum =
  iCanAdd.createMyth("addToSum")<number>({
    reduce: (state, action) =>
      state.set("sum", state.get("sum") + action.payload),
  });

A package can have any number of myths.

Action

To create an action based on a myth, use its create function. You can then dispatch this action normally:

store.dispatch(addToSum.create(8));

Store

You get a store from a set of mythic packages, which has all the appropriate reducers and epics already in place:

type NonPrivateState = { foo: string };
const configureStore = makeConfigureStore<NonPrivateState>()({
  packages: [
    iCanAdd,
  ],
});
export const store = configureStore({ foo: "bar" });

Epics: their definition

Epics can be defined using two different shorthand methods:

export const addToSum =
  iCanAdd.createMyth("addToSum")<number>({

    reduce: (state, action) =>
      state.set("sum", state.get("sum") + action.payload),

    thenDispatch: [
      (action, state) =>
        state.get("sum") - action.payload < 100 && 100 <= state.get("sum")
          ? of(sendNotification.create({message: "Just passed 100!"}))
          : EMPTY,
    ],

    andAlso: [
      {
        // Halve the sum every time an error action happens
        when: action => action.error ?? false,
        dispatch: (action, state, addToSum_) =>
          of(addToSum_.create(-state.get("sum") / 2)),
      },
    ],

  });

The first method uses thenDispatch: [] to define actions which should be dispatched when actions of the defined type are dispatched, and the second method uses andAlso: [] to generate actions based on a custom predicate. Since the type being defined is not available for reference yet, it is passed as third argument to the dispatch function.

Testing

To test the actions of a mythic package, you can use the testMarbles(...) method. Note that this only tests the epics, without evaluating reducers.

Support

If you experience an issue while using this package or have a feature request, please file an issue on the issue board and add the pkg:myths label.

License

BSD-3-Clause