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

js-workflows

v0.0.3

Published

A simple state machine workflow implementation for JS

Downloads

86

Readme

JS-Workflows

This is a simple implementation of state machine workflows for JS.

This packages makes it easy to transition between states or pages/components in a front-end application by defining a journey in a simple object.

Usage

Defining a workflow

Workflows are objects with id, firstStep and a list of steps defined.

Steps are definitions of all steps that can occur in this workflow. A step can start another workflow to allow moving between them.

{
    id: 'demo-workflow',
    firstStep: 'foo',
    steps: {
        foo: {
            execute: () => {},
            nextStep: 'bar',
            cancelStep: 'cancelStep',
            errorSteps: {
                '400': 'error400',
                '401': 'error401',
                fallback: 'errorFallback'
            }
        },
        bar: {
            execute: () => {}
        },
        cancelStep: {
            execute: () => {}
        },
        error400: {
            execute: () => {}
        },
        error401: {
            execute: () => {}
        },
        errorFallback: {
            execute: () => {}
        }
    }
}

Types

Workflow

| Name | Type | Required? | description | | - | - | - | - | | id | string | yes | A unique ID for the workflow | firstStep | string | yes | Name of the first step to run, must exist in the list of steps | steps | Record<string, Step> | yes | List of all steps in this workflow

Step

| Name | Type | Required? | description | | - | - | - | - | | execute | function | yes | Function to execute when this step is called | | nextStep | string | no | Name of the step to move onto when onNextStep is called | | cancelStep | string | no | Name of the step to move onto when onCancelStep is called | | errorSteps | Record<string, string> | no | A key value pair of HTTP status codes mapped to which step to move onto when an error with that code occurs. fallback can also be used to catch all other errors.

Defining steps in a workflow

To allow a step to move onto to the next step onNextStep has to be called. All internal functions are exposed on the engine object passed in the data prop.

To handle nextStep:

const demoFunction = (data) => {
    // Your code
    data.engine.onNextStep()
}

To handle cancelStep:

const demoFunction = (data) => {
    // Your code
    data.engine.onCancelStep()
}

To handle errorSteps:

const demoFunction = (data) => {
    try {
        // Your code
    } catch (error) {
        data.engine.onErrorStep(error)
    }
}

Using a workflow

Use the WorkflowEngine constructor to create an instance of an engine, passing in the workflow you want to execute, the callback to be executed when workflow finished successfully and any initial data. callback and data are optional.

Calling the constructor does not start the workflow, this is to allow for a delayed execution. Call startWorkflow to initiate it.

const engine = new WorkflowEngine(workflow, callback, data)
engine.startWorkflow()

Demos

[todo]

Contribute

[todo]

Special thanks

Special thanks to @joffyb without whom this would not have been possible :heart:

License

ISC License

Copyright 2023 Pawel Dworzycki

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.