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

@ethossoftworks/redux-effect-reducer

v1.2.2

Published

Redux middleware for handling side-effects declaratively using reducer-like functions

Downloads

2

Readme

Redux Effect Reducer

Redux Effect Reducer works by using a reducer-like function (an effect reducer) for side-effects. The effect reducer takes the current application state and an action as input and responds with an Effect object which describes the effect the middleware should execute. Redux Effect Reducer middleware then executes the effect returned from the effect reducer. The same input to the effect reducer will always produce the same output.

Documentation

Features

  • First class type support (written in TypeScript)
  • Standard Redux middleware
  • Async/Await based
  • Multiple effects can respond to the same action
  • A single effect can respond to multiple actions
  • Composable effects
  • Testable
  • No external dependencies
  • Optional effect logging

Installation

redux-effect-reducer can be installed using NPM or Yarn. The scripts provided by the NPM package are UMD scripts and will also work as direct script tags.

Install with Package Manager

yarn add @ethossoftworks/redux-effect-reducer

Install with Script Tags

You may find the scripts in either the NPM package or from releases. Both the core and effects scripts must be loaded to use this library.

Note: The effects scripts must be loaded before the core script. The core script depends on the effects script.

<script src="redux-effect-reducer.effects.js"></script>
<script src="redux-effect-reducer.core.js"></script>
<script>
    // ReduxEffectReducer.core
    // ReduxEffectReducer.effects
</script>

Usage

redux-effect-reducer works with existing reducers and action creators, so you won't have to modify any existing code. To begin using redux-effect-reducer create an effect reducer and add the middleware to your store.

Core Concepts

Effect Reducer

  • Effect reducers are very similar to normal state reducers. The only difference is that instead of returning new state, the effect reducer will return an Effect (or void if no effect should be executed).
  • Effect reducers always have the latest state because they take the state returned from state reducers as an input parameter. There is no need to call getState() like you have to do with Thunks.

Effect

  • Effects are simply declarative objects; they do not execute anything themselves. They only describe the effect that the middleware should execute.
  • Effects are composable. It is possible to build up effect chains by returning effects from effects.

1. Create an Effect Reducer

// reducer.ts

import { Effect, run } from "@ethossoftworks/redux-effect-reducer/effects"

export function myEffectReducer(state: MyState, action: Action): Effect | void {
    switch (action.type) {
        case "MY_ACTION":
            // The `run` effect creator function returns a `RunEffect` and tells
            // the middleware run the provided function in response to an action
            return run(() => console.log("My Effect Ran!"))
    }
}

2. Add middleware to store

// store.ts

import { createEffectReducerMiddleware } from "@ethossoftworks/redux-effect-reducer"

const effectMiddleware = createEffectReducerMiddleware(myEffectReducer)
export const store = createStore(reducer, applyMiddleware(effectMiddleware))

When you dispatch the action "MY_ACTION" you will see "My Effect Ran!" in the console.

Example Project

For more examples, look at the Example project.