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-create-actions

v1.0.0

Published

Redux action creator building utilities

Downloads

4

Readme

redux-create-actions

Build Status npm js-standard-style

redux-create-actions is a library that helps construct FSA compliant action creators and massively decreasing the amount of boilerplate necessary to generate constants and action creators.

Getting started

install

$ npm install --save redux-create-actions

or

$ yarn add redux-create-actions

Usage

Suppose we need to generate action creators and constants to filter loaded todos and also fetch remote todos

import { module, createAction, createAsyncAction } from 'redux-create-actions'

const {
  actions,
  constants
} = module('@todos', {
  filterTodos: createAction('FILTER_TODOS'),
  fetchTodos: createAsyncAction('FETCH_TODOS')
})

The module block noted in the example above would return an object with a shape of

{
  constants: {
    'FILTER_TODOS': '@todos/FILTER_TODOS',
    'FETCH_TODOS': '@todos/FETCH_TODOS',
    'FETCH_TODOS_START': '@todos/FETCH_TODOS_START',
    'FETCH_TODOS_SUCCESS': '@todos/FETCH_TODOS_SUCCESS',
    'FETCH_TODOS_FAILURE': '@todos/FETCH_TODOS_FAILURE'
  },
  actions: {
    filterTodos: Fn,
    fetchTodos: Fn
      - fetchTodos.start: Fn
      - fetchTodos.success: Fn
      - fetchTodos.failure: Fn
  }
}

Documentation

createAction

createAction(actionType: string) -> ActionCreator

Utility function for generating action creators

ActionCreator = (payload, meta) -> { type, payload, meta }

createAsyncAction

createAsyncAction(actionType: string) -> AsyncActionCreator

Utility function for generating async action creators. This will output a function (action creator) with start, success, and failure invokable properties for ease of use.

AsyncActionCreator = ActionCreator
AsyncActionCreator.start = ActionCreator
AsyncActionCreator.success = ActionCreator
AsyncActionCreator.failure = ActionCreator

module

module(namespace: string, actions: Object) -> { constants, actions }

namespace optional string to scope actions generated by module. actions object of action creators

{
  filterTodos: createAction('FILTER_TODOS'),
  fetchTodos: createAsyncAction('FETCH_TODOS')
}

Motivation

Redux brought along many great things to the world of software development, unfortunately that came with a bit of extra boilerplate. While the boilerplate is manageable repeating the same code time and time again grows tiresome, especially when it comes to writing constants and action creators.

Take a usual file that exports constants and action creators for both sync and async actions.

const LOAD_POSTS = '@home/LOAD_POSTS'
const LOAD_POSTS_REQUEST = {
  START: '@home/LOAD_POSTS_REQUEST_START',
  SUCCESS: '@home/LOAD_POSTS_REQUEST_SUCCESS',
  FAILURE: '@home/LOAD_POSTS_REQUEST_FAILURE'
}

export const constants = {
  LOAD_POSTS,
  LOAD_POSTS_REQUEST
}

const loadPosts = ({ payload }) => ({ type: LOAD_POSTS, payload })
const loadPostsRequest = {
  start: ({ payload }) => ({ type: LOAD_POSTS_REQUEST.START, payload }),
  success: ({ payload }) => ({ type: LOAD_POSTS_REQUEST.SUCCESS, payload }),
  failure: ({ payload }) => ({ type: LOAD_POSTS_REQUEST.FAILURE, payload })
}

export const actions {
  loadPosts,
  loadPostsRequest
}

Writing action creators and constants like this quickly becomes very tedious work, and that's where redux-create-actions comes in. The previous module would condense down to

import { module, createAsyncAction } from 'redux-create-actions'

const {
  constants,
  actions
} = module('home', {
  loadPosts: createAsyncAction('LOAD_POSTS')
})

License

MIT