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

fsaction

v1.1.0

Published

Flux Standard Action object creator.

Downloads

5

Readme

fsaction Build Status NPM version

Flux Standard Action object creator.

A little shorthand to help creating flux standard action objects.

Installation

npm install fsaction

Usage

import fsaction from 'fsaction';

expect(fsaction('INCREMENT')).to.deep.equal({
	type: 'INCREMENT'
});
expect(fsaction('INCREMENT', 42)).to.deep.equal({
	type: 'INCREMENT',
	payload: 42
});
expect(fsaction('INCREMENT', 42, 'foo')).to.deep.equal({
	type: 'INCREMENT',
	payload: 42,
	meta: 'foo'
});
expect(fsaction('INCREMENT', new Error('foo'))).to.deep.equal({
	type: 'INCREMENT',
	payload: Error<'foo'>,
	error: true
});
expect(fsaction('INCREMENT', (action) => 42, (action) => 'foo'))).to.deep.equal({
	type: 'INCREMENT',
	payload: 42,
	meta: 'foo'
});

API

fsaction(type: string, payload?: any, meta?: any) : object

When payload or meta are functions, they - and any functions they return - will be called until something else than a function is returned.

expect(fsaction('INCREMENT', () => () => () => 42))).to.deep.equal({
	type: 'INCREMENT',
	payload: 42
});

payload or meta functions receive action object as their 1st argument.

payloadCreator(action: object) : payload | payloadCreator

In payload(), this object only has a type property.

In meta(), this object has type, maybe payload, and maybe error properties.

You should treat this object as read only, as that is the resulting FSA object, and modifying it in non-standard way will break FSA compliance.

fsaction.error(type: string, payload?: any, meta?: any) : object

Forces error flag on the resulting action object.

Aliases: fsaction.err(), fsaction.e()

Why not redux-actions?

My actions are usually complex and async, and I prefer them returning a promise instead of an object with promise on its payload property, so combined with redux-thunk and redux-promise I can do stuff like this:

const deleteUser = id => async dispatch => {
	await dispatch(deleteUserData(id));
	return fsaction(DELETE_USER, id);
};

If deleteUserData() was created with redux-actions' createAction(), I'd have to do:

	await dispatch(deleteUserData(id)).payload

which just feels weird to me, and doesn't seem right ™.

In other words, fsaction provides more control over how your actions look like, and how they work. And you can easily use an arrow to replace the redux-actions' createAction():

const payloadCreator = amount => amount;

// redux-actions' `createAction()`
const increment = createAction('INCREMENT', payloadCreator);

// fsaction
const increment = amount => fsaction('INCREMENT', payloadCreator(amount));

License

ISC License (ISC)