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

redecorate

v0.2.1

Published

Simple module for reducing immutable nested properties in Redux applications.

Downloads

12

Readme

Redecorate

Simple module for reducing immutable nested properties in Redux applications.

forthebadge forthebadge forthebadge

Getting Started

import {apply} from 'redecorate';

// ...

const model = apply(state)('name.places', cursor => {
    return [ ...cursor, { name: 'Malta' } ];
});

Redecorate allows you to easily handle nested state in your Redux reducers – even after specialising your reducers using combineReducers.

Helpers

Common patterns are found throughout Redux's reducers, which is why Redecorate provides a handful of helper functions to make the reducing process simpler and more readable for fellow developers.

In the following examples we'll assume we have the following state:

const state = {
    name: {
        first: 'James',
        surname: 'Bradfield';
    },
    age: 46,
    songs: ['A Design For Life', 'Motorcycle Emptiness', 'Generation Terrorists'],
    albums: [
        { name: 'The Holy Bible', released: 1994 },
        { name: 'Everything Must Go', released: 1996 },
        { name: 'This Is My Truth, Tell Me Yours', released: 1998 }
    ]
};

We can use the set helper to modify properties on the age literal:

apply(state)('age', set(47));

Furthermore we're able to able to use the set function for adding properties to the name object:

apply(state)('name.middle', set('Dean'));

Adding an item to the songs is as easy as using the add function — you can pass multiple arguments to add many items onto the array:

apply(state)('songs', add('If You Tolerate This Your Children Will Be Next'));

Similarly you can use the remove function to remove items from the aforementioned array — again you can use the nature of the add and remove multivariate functions to supply more than one item:

apply(state)('songs', remove('Motorcycle Emptiness', 'Generation Terrorists'));

Removing items from an array of objects is slightly more difficult:

apply(state)('albums', remove({ released: 1994 }));

You can also pass multiple arguments to the remove function — however if you want to remove items that are either { released: 1994 } or { name: 'Everything Must Go' } then simply pass multiple arguments to the remove function:

apply(state)('albums', remove({ name: 'Everything Must Go' }, { released: 1994 }));

:bulb: Have an idea for Redecorate's helper functions?