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

axios-action-creators

v0.2.2

Published

A set of action creators that make it easier to work with axios and redux.

Downloads

1

Readme

Axios Action Creators

npm version Build Status JavaScript Style Guide

Axios Action Creators makes it really easy to deal with API responses. Simply define the action creators and then call them when you receive the response to get standardised actions.

Installation

Using npm

npm install axios-action-creators

...or using yarn

yarn add axios-action-creators

Usage

Basic Usage
import axios from 'axios'
import { REQUEST, SUCCESS, FAILURE } from 'axios-action-creators'

// (1) Define action types
export const GET_USERS_REQUEST = 'GET_USERS_REQUEST'
export const GET_USERS_SUCCESS = 'GET_USERS_SUCCESS'
export const GET_USERS_FAILURE = 'GET_USERS_FAILURE'

// (2) Define action creators – just pass in the type
const getUsersRequest = REQUEST(GET_USERS_REQUEST)
const getUsersSuccess = SUCCESS(GET_USERS_SUCCESS)
const getUsersFailure = FAILURE(GET_USERS_FAILURE)

// (3) Call the action creators to get the actions
export const getUsers = () => (dispatch) => {
  // Resolves to a action with type GET_USERS_REQUEST
  dispatch(getUsersRequest())
  return axios.get('/users')
    // If successful dispatch GET_USERS_SUCCESS action
    .then(res => dispatch(getUsersSuccess(res)))
    // If failure dispatch GET_USERS_FAILURE action
    .catch(err => dispatch(getUsersFailure(err)))
}

All action creators optionally take an object which can be used to modify the action.

Valid keys in this object are:

  • meta add arbitrary data to a meta property in the action.
  • schema (only SUCCESS / FAILURE) a normalizr schema to normalise the response.
Example usage setting meta and schema
import { schema } from 'normalizr'
const getGistsRequest = SUCCESS('GET_GISTS_REQUEST')
const getGistsSuccess = SUCCESS('GET_GISTS_SUCCESS')

export const getGists = () => dispatch => {
  dispatch(getGistsRequest({
    meta: { requestedAt: Date.now() }
  }))
  axios.get('/username/gists')
    .then(res => dispatch(getGistsSuccess(res, {
      meta: { responseAt: Date.now() },
      schema: new schema.Array('gists')
    })))
}

The dispatched actions would look something like this

// getGistsRequest
{
  type: GET_GISTS_REQUEST,
  meta: {
    requestedAt: 1513176647405
  }
}

// getGistsSuccess
{
  type: GET_GISTS_SUCCESS,
  payload: {
    entities: {...},
    result: [15564, 27377, ...]
  },
  meta: {
    responseAt: 1513176648004,
    response: {...}
  },
}

The original unmodified response, if available, is always stored in meta.response. Request data, either raw or normalised, is always stored in payload.