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

action-hero

v1.2.0

Published

A tool for generating action objects.

Downloads

6

Readme

Action Hero

Action Hero is a utility library for creating action objects. These can be used with flux architectures like Redux, or more generally any time you need a convenient way to instantiate objects of the form {type: "myType", payload: {...}}.

Action Hero currently exposes three functions.

createAction simply returns a new action with type and payload properties:

import {createAction} from "action-hero";

var mySimpleAction = createAction("myType", "myPayload");
// gives you {type: "myType", payload: "myPayload"};

var noPayload = createAction("noPayload");
// gives you {type: "noPayload"};

var thisDoesNotWork = createAction();
// throws error requesting a type.

var neitherDoesThis = createAction({foo: "bar"});
// throws error requesting a string type.

createActionCreator returns an actionCreator function whose type property has been bound to the provided type and which takes, as an optional paramter, a payload parser function that allows you to pass multiple arguments in and synthesizes them into a single valid payload.


import {createActionCreator} from "action-hero";

// in its most vanilla mode, it works like this:
var myActionCreator = createActionCreator("myType");

var action = myActionCreator();
// returns {type: "myType"};

var action2 = myActionCreator("payload");
// returns {type: "myType", payload: "payload"};

var action3 = myActionCreator("payload", "some", "other", "args");
// returns {type: "myType", payload: "payload"}
// the other args are ignored.

// however, createActionCreator takes an optional argument which is a payload parser
// if you provide it, you'll be able to call the resulting action creator with
// whatever arguments you want.
var complexActionCreator = createActionCreator("myType", function(a, b) {
  return a + b;
});

var action = complexActionCreator(2, 2);
// returns {type: "myType", payload: 4};

Finally, createBoundActionCreator allows you to specify a dispatcher into which created actions should be automatically piped. Use this if every time you create an action you simply apply it to the same dispatcher function - this way, that application gets handled seamlessly behind the scenes for you.

import {createBoundActionCreator} from "action-hero";

var dispatcher = function(action) {
  console.log("An action was just dispatched into me.");
  console.log("type:", action.type);
  console.log("payload:", action.payload);
};

var payloadParser = function(a, b) {
  return a + b;
};

var boundActionCreator = createBoundActionCreator("myType", payloadParser, dispatcher);

boundActionCreator(2, 5);
// An action was just dispatched into me.
// type: "myType"
// payload: 7

// as in our previous example, the payloadParser is optional
var simpleBoundActionCreator = createBoundActionCreator("myType", dispatcher);
simpleBoundActionCreator("myPayload");
// An action was just dispatched into me.
// type: "myType"
// payload: 7