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

f1-redux-utils

v1.0.8

Published

Simple utilities for Redux

Downloads

17

Readme

f1-redux-utils

My utilities for Redux projects.

Install

npm i f1-redux-utils --save

Usage

The module uses ES6 syntax.

Action Creators

A very simple action creation utility.

import { createAction, createActions } from 'f1-redux-utils/actionCreators'
const [act1, act2] = createActions('test1', 'test2')
const act3 = createAction('test3')

Now you can use act1() to create a new action. The parameter will be placed in the "payload" field. It takes an optional error parameter which will be placed in the "error" field.

expect(act1()).to.eql({
  type: 'test1'
})
expect(act2('foo')).to.eql({
  type: 'test2',
  payload: 'foo'
})
expect(act3(null, 'error')).to.eql({
  type: 'test3',
  error: 'error'
})

Load Action Container

Container wrapper that will trigger an action when it is rendered (in componentWillMount). Use together with connect, for a container that needs to load some data when it is initially loaded.

import { connect } from 'react-redux';
import loadaction from 'f1-redux-utils/loadaction'

const mapStateToProps = state => ({
  id: state.location.id
})
const AdminContainer = loadaction({ id } => loadTemplateById(id))(AdminPage);
// take care that the connect() call is after the loadaction call, so that the
// mapped state and actions are available as props within the callback
export default connect(mapStateToProps, adminActions)(AdminContainer);

With the autoConnect parameter an action creator can be passed instead, enabling the connect call to be ommitted. The function will be passed the props.

import { connect } from 'react-redux';
import loadaction from 'f1-redux-utils/loadaction'

const AdminContainer = loadaction(adminActions.loadTemplateById, true)(AdminPage);

Unload Action Container

Equivalent to Load Action Container, for unmount instead of mount.

Handle Prefixed Actions

Helper function to write a reducer that will act on all actions that have a certain prefix. A default state can be provided as well.

This example will handle the PROJECT_LIST_ON_FILTER action:

const list = handlePrefixedActions('PROJECT_LIST', {
  ON_FILTER: (state, action) => ({...state, filter: action.payload })
}, { filter: '' })

It's also possible to use this to handle most prefixed action but some absolute ones by prefixing those with a forward slash:

const list = handlePrefixedActions('PROJECT_LIST', {
  ON_FILTER: (state, action) => ({...state, filter: action.payload }),
  "/APP_EVENT": (state, action) => ({...state, appDidSomething: true})
}, { filter: '' })