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

tidepool-standard-action

v0.1.1

Published

Tidepool's (enforceable!) standard for redux action objects.

Downloads

764

Readme

tidepool-standard-action

Travis CI

Justification

(Or jump to The Standard.)

Tidepool's (enforceable!) standard for redux action objects.

Inspired by flux-standard-action but tailored specifically to Tidepool's needs.

Yes, we are aware of the irony, and we've seen that XKCD comic.

We've created this repository because the flux-standard-action (FSA) project failed us in two places:

  1. The isFSA() function exposed by FSA does not validate the action objects to the level of detail that we require in our heavily-tested applications. 😕

  2. FSA's decision to represent error actions with a Boolean true in the error field, and a JavaScript Error object as the payload causes us problems in a small but significant number of cases where we need other information in the payload besides the Error object in order to update our state tree accurately. In other words, we agree with many of those who chimed in on FSA's Issue #17.

In short, since we (at Tidepool) have several applications where we need to adhere to a standard for actions (and validate that standard in unit tests!), we have decided1 to create our own standard and utility for this purpose. Others are welcome to adopt our standard as well, but we're not going to be evangelical about it. 😉

1: For posterity: @jebeck, in particular, is to blame here, with encouragement from @GordyD.

The remainder of this README is a modified version of FSA's README.

Introduction

A Tidepool-friendly standard for redux action objects. Because we needed it.

Motivation

It's much easier to work with redux actions if we can make certain assumptions about their shape. For example, all redux actions have a type identifier field. Many redux actions also include some payload of data that will be used by the reducers to modify the state tree. Defining a common standard for these patterns enables the creation of useful tools and abstractions and makes our lives easier as developers working on more than one app.

Design goals

  • Human-friendly. TSA actions should be easy to read and write by humans.
  • Useful. TSA actions should enable the creation of useful tools and abstractions.
  • Simple. TSA should be simple, straightforward, and opinionated in its design. (Loose standards aren't easily enforceable!)

Example

A basic Tidepool Standard Action (TSA):

{
  type: 'ADD_TODO_SUCCESS',
  payload: {
    text: 'Fry up some bacon.'  
  }
}

Error Example

A TSA that represents an error:

{
  type: 'ADD_TODO_FAILURE',
  error: new Error('Error adding a TODO :('),
  payload: {userId: 'a1b2c3'}
}

Actions

An action MUST

  • be a plain JavaScript object.
  • have a type property.

An action MAY

  • have an error property.
  • have a payload property.
  • have a meta property.

IFF an action has an error property, the error property MUST

  • be a JavaScript Error object.

IFF an action has a payload property, the payload property MUST

  • be a plain JavaScript object.

IFF an action has a meta property, the meta property MUST

  • be a plain JavaScript object.

An action MUST NOT include properties other than type, payload, and error, and meta.

type

The type of an action identifies to the consumer the nature of the action that has occurred. In a TSA, type MUST be a JavaScript String constant.

error

The optional error property MUST be a JavaScript Error object. It indicates that the action be interpreted as an error action.

payload

The optional payload property MUST be a plain JavaScript object. It represents the payload of the action. Any information about the action that is not the type or status of the action should be part of the payload object.

meta

The optional meta property MUST be a plain JavaScript object. It is intended for any extra information that is not part of the payload.

Testing utility

This module (tidepool-standard-action) is published on npm. It exports an isTSA utility function that may be used as follows:

ES5, assuming use of CommonJS modules:

var isTSA = require('tidepool-standard-action');

var action = {...};

isTSA(action);

ES6/ES2015:

import isTSA from 'tidepool-standard-action';

const action = {...};

isTSA(action);

isTSA returns true if action complies with the standard described above and false otherwise.