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

redux-wings

v1.0.0-beta.2

Published

It gives your Redux wings!

Downloads

167

Readme

redux-wings

"It gives your Redux wings!"

A lightweight, dependency-free collection of utilities for streamlining Redux development by letting you quickly make synchronous or asynchronous actions. Designed to work great with the Redux Ducks pattern for modular and consistent Redux apps that scale on teams and projects that go beyond your typical CRUD systems.

Installation

npm i --save-dev redux-wings

Library

createStateSlice

Creates { actions, reducers } in order to augment and generate a specific redux app state slice -- this is the bread and butter here.

Example @ ${rootSrc}/modules/tasks/tasksSlice.js

import { createStateSlice } from 'redux-wings';
import getTasks from 'api'; // async function

const initialReducerState = {

    tasks: [],

    // auto-generated/managed by creating the
    // async action of "tasks", but listed for
    // clarity's sake

    getTasksState: 'idle'
};

const { actions, reducer } = createStateSlice({
    namespace: 'tasks',
    initialReducerState,
    actions: {

        // auto-generates the constants:

        // 'tasks/GET_TASKS_REQUEST'
        // 'tasks/GET_TASKS_SUCCESS',
        // 'tasks/GET_TASKS_ERROR'

        // as well as the actions
        // getTasksRequest,

        // and appends these to output actions

        asyncRequest: getTasks,
        asyncReducers: {

            // note that we do not need to do anything
            // to update getTasksState, this will auto
            // set itself to 'success' here

            success: (state, { type, payload }) => {
                return {
                    ...state,
                    todos: payload
                }
            },

            // getTasksState also auto-updates itself to
            // "error" here, and same for "request"

            error: (state, { type, payload }) => {
                return {
                    ...state,
                    todos: []
                }
            },

            // getTasksState also auto-updates itself to
            // "error" here, and same for "request"

            request: (state, { type, payload }) => {
                return {
                    ...state,
                    todos: []
                }
            }
        }
    }
});

sliceNamespace : String

The redux namespace as camelCase that this slice belongs to. For example: session, users, userTransactions, etc.

actions : String | Object

A list of actions either specified as a camelCase string representing the action namespace or an Object which determines Async action namespaces to create.

If specified as a String, will automatically generate namespace of action constant in UPPER_SNAKE_CASE, as well as a default camelCase'd function which will optionally just funnel a payload if available to the listening reducer when action dispatched.

If specified as an object, it will take an interface which would represent an object containing namespace (camelCase'd) and optionally if you would like to auto-generate asynchronous behavior as well as XXX_SUCCESS, XXX_ERROR and XXX_REQUEST boilerplate, requestHandler and stateVariable. These are used when we generate an asyncReducer (seen in final example in later section) which auto-augments functionality to toggle your stateVariable specified automatically.

AsyncStates : IDLE | ERROR | PROCESSING | SUCCESS

A string enum that represent for four different possible asynchronous states, those being:

IDLE : an action is idle when it has not been dispatched and the store has just initiated (and not yet a need to have checked it). It may also be reset to this state on success or error as specified by a user in reducer manually if they prefer to go with this paradigm (or after some time incrementally in an action dispatcher).

PROCESSING : an action that has been dispatched, and currently waiting on async action to result in SUCCESS or ERROR.

SUCCESS : an action which has successfully completed without errors after PROCESSING.

ERROR : an action which has contained some errors along the way (which may or may not have completed) after it was PROCESSING.

Example usage:

Can be imported either

  1. with enums directly from package module
    import {
        IDLE,
        SUCCESS,
        ERROR,
        PROCESSING
    } from 'redux-wings';

or

  1. as a namespace
import { AsyncStates } from 'redux-wings';

Note that these are simply strings of idle, processing, success or error. The constants are provided to help centralize or prevent errors.

Important Note: to properly process your existing state without declaring your async variable twice, the asyncReducer must be specified first (composeReducer actually processes reducer arguments from right-to-left).

Usage

TODO: document new version usage

Contributing

If you have any issues, please feel free to submit as any feedback and iteration is always appreciated! P.R.s and discussion for changes are always absolutely welcome and encouraged.

In terms of the philosophy behind this, while we would like to preserve backwards compatibility, the main goal is to make life easier without cutting corners or losing flexibility that Redux provides.

License

Open Source MIT