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-semantic-action-middleware

v1.0.0

Published

Redux middleware that lets you define actions as meaningful units, without OOP.

Downloads

8

Readme

redux-semantic-action-middleware

Redux middleware that lets you define actions as meaningful units, without OOP.

Description

This is redux middleware that lets you define & run asynchronous actions in a way that aligns the semantics of those objects with the code used to represent them.

It treats all actions as potentially asynchronous and does not use both functions & objects to represent them. All actions are objects (asynchronous objects have to have a .run() property).

Additionally, the action type is an object and not a string.

It is different from other middleware (like redux-thunk), in that it does not conflate the concept of a stateful action object with a thunk that is meant to be executed, but never shown to reducers.

In other words, IMO, it provides better separation of concerns and results in code that more accurately represents the intent of its author.

It is also different from middleware like redux-action-class-middleware in that it doesn't use ES6 classes (a virtue to some).

Reasons to use this instead of alternatives

  • You don't like treating functions that reducers never see in the same way as objects reducers do see.
  • You don't like naming factory functions after the actions themselves. (ie, function myAction() which creates the actual action).
  • You don't like ES6 classes.

Reasons not to use this instead of alternatives

  • You don't like having to write the extra code.
  • You like using switch statements in reducers instead of using reference equality.
  • You think creating an object or class to encapsulate the concept of a particular action is the same as creating a function that returns the action object.

It's a toss-up. Go with your gut.

Example

// sync action with no extra logic
const todosFetched = {
    make: function (issues) {
        return {type: todosFetched, issues: issues}
    }
}

// async action that starts an AJAX request to get the TODO entities
const fetchTodos = {
    make: function () {
        return {type: fetchTodos}
    },
    run: function(action, dispatch) {
        API.fetchTodos().then(function (issues) {
            dispatch(todosFetched.make(issues))
        })
    }
}

let reducer = function (state, action) {
    if (action.type == fetchTodos) {
        return Object.assign({}, state, {loading: true})
    }

    if (action.type == todosFetched) {
        return Object.assign({}, state, {issues: action.issues, loading: false})
    }

    return state
}