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

novux

v1.0.3

Published

Easily update & reset redux state

Downloads

1,413

Readme

novux

novux lets you to write Redux code simpler & faster by using an opinionated reducer generator.

  1. less boilerplate: instead of having to write and maintain dozens of actions creators, simply change state using two actions, update or reset.
  2. less maintenance: reduce the number of tests you have to write to only focus on business logic — all reducer action creator tests are handled by novux
  3. code faster: easily declare and describe state changes to make coding & collaboration easier, even as state changes become more complex

Installation

npm install novux
npm run build
npm run test

Get started

Create your reducers

import createReducer from 'novux';

const initialStates = {
  user: {
    name: 'Michael',
    company: 'Nova Credit'
  },
};

const userReducer = createReducer('user', initialStates.user);

Dispatch actions

novux lets you run Redux by handling only two actions: update and reset.

update is used to update the state of a single reducer given an object. reset is used to reset the reducer to its initial state or reset specific keys to their initial values.

Both actions have the following signature: actionName(reducerName, tag, options)

  • actionName: how is the state being changed?
  • reducerName: which reducer is being affected?
  • tag: why is this change relevant?
  • options: what values are affected?

Example:

import { update, reset } from 'novux';

dispatch(update('user', 'Change username', {
	username: 'Stash',
}));

dispatch(reset('user', 'Reset the initial state', {
	reset: [],
}));

dispatch(reset('user', 'Reset specific keys', {
	reset: ['username'],
}));

// dispatch is provided by redux: http://redux.js.org/docs/api/Store.html#dispatchaction

Use dot notation paths

When reseting state, you can also pass in paths in dot notation

dispatch(reset('user', 'Reset paths', {
	reset: ['address.street'],
}));

// if a path is defined in the initial state, it will be reset to its initial value
// if a path is undefined in the initial state, `novux` will seek the longest sub path defined in the initial state and reset

Why a tag

Using the tag string instead of an action name to define a state change lets you describe state changes programatically.

The tag is included in the updated state under the key _lastAction, allowing you to keep track of what action last affected a specific reducer in your dev tools.

const consent = true;
const { username } = getState().user;
dispatch(update('user', `${username} ${consent ? 'grants' : 'revokes'} consent`, {
	consent,
}));

Connecting the dots

novux can help you declare increasingly complicated sets of state updates in simple and consistent ways.

const toggleConsent = consent => (dispatch, getState) => {
	const { username } = getState().user;
	dispatch(update('user', `${username} ${consent ? 'grants' : 'revokes'} consent`, {
		consent,
	}));

	if (!consent) {
		dispatch(update('app', `Show error & disable button`, {
			error: {
				msg: 'You need to grant consent to proceed',
				type: 'flash',
			},
			button: { able: false }
		}));
	}
};
// this example makes use of redux-thunk to easily access dispatch and state