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-collections

v1.4.4

Published

One-liners for creating redux reducers and action creators for scrollable, editable lists. No dependencies.

Downloads

6

Readme

npm version Build Status

Redux Collections

One-liners for creating redux reducers and action creators for scrollable, editable lists. No dependencies.

This module provides methods for creating reducers for ordered or key-value state to be used in redux apps.

Usage

Using tools like normalizr one can store backend responses in normalized form, such as:

{
  posts: {
    'on-the-electrodynamics-of-moving-bodies': {
      title: "Hello",
      author: 15,
      comments: {
        items: [1, 4, 5]
      },
      likers: {
        error: "Network Timeout"
        items: [1, 5, 3, 7]
      }
    },
    'on-physical-lines-of-force': { /* ... */ },
    /* ... */
  },

  comments: {
    1: {
      author: 2,
      text: "Some text",
      isUpdating: true
     },
     2: { /* ... */ },
     /* ... */
  },

  users: {
    1: { name: "Kierkegaard" },
    2: { name: "Hegel" },
    /* ... */
  },

  recentPosts: {
    items: ['on-physical-lines-of-force', /*, ... */],
    isLoading: true,
  },
}

/* etc. */

Aim of this package is to maintain such a structures, including appending, prepending, and setting loading and error states.

Creating Store


import { combineReducers, createStore } from 'redux';

import {
  collection,
  map,

  collectionIsAppending,
  mapAdd,
  collectionAppend,
  collectionError
  /* , ...  
    See list of available action creators below
  */
  } from 'redux-collections';


const reducer = combineReducers({
    posts: map('posts', ['comments', 'likers']),
    users: map('users'),
    comments: map('comments'),
    recentPosts: collection('recentPosts')
  });

const store = createStore(reducer);

const { dispatch } = store;

Dispatching Actions


/* Somewhere before fetching response */

  dispatch(collectionIsAppending('recentPosts'));

/* Somewhere after fetching and normalizing response */

  dispatch(mapAdd('posts', {
      'elements': { /* ... */ },
      'philosophiae-naturalis': { /* ... */ }
      /*, ... */
  }));

  dispatch(mapAdd('users', {
      12: { /* ... */ },
      13: { /* ... */ }
      /*, ... */
  }));

  dispatch(mapAdd('comments',  {
      115: { /* ... */ },
      116: { /* ... */ }
      /*, ... */
  }));

  dispatch(collectionAppend('recentPosts', [
    'elements',
    'philosophiae-naturalis'
    /*, ... */
  ]);

  /* Somewhere after fetch error */

  dispatch(collectionError('recentPosts', 'Network Timeout'));

Fetching child collection in a map:


  dispatch(collectionIsAppending(
    'comments',
    'posts',
    'philosophiae-naturalis'
  ));

  dispatch(mapAdd('comments', /* ... */ );

  dispatch(collectionPrepend(
    'comments',
    [ 18, 19 /*, ... */],
    'posts',
    'philosophiae-naturalis'
  );

Modules

redux-collections/actionCreators

redux-collections/actionCreators~collectionAppend ⇒ Object

Appends items to the collection

Kind: inner property of redux-collections/actionCreators
Returns: Object - action

| Param | Type | Description | | --- | --- | --- | | collection | string | | | items | array | | | [map] | string | Name of parent map where collection lives | | [parentId] | Number | String | Key of parent map where collection lives |

redux-collections/actionCreators~collectionPrepend ⇒ Object

Prepends items to the collection

Kind: inner property of redux-collections/actionCreators
Returns: Object - action

| Param | Type | Description | | --- | --- | --- | | collection | string | | | items | array | | | [map] | string | Name of parent map where collection lives | | [parentId] | Number | String | Key of parent map where collection lives |

redux-collections/actionCreators~collectionIsAppending ⇒ Object

Sets isAppending state on the collection

Kind: inner property of redux-collections/actionCreators
Returns: Object - action

| Param | Type | Description | | --- | --- | --- | | collection | string | | | items | array | | | [map] | string | Name of parent map where collection lives | | [parentId] | Number | String | Key of parent map where collection lives |

redux-collections/actionCreators~collectionIsPrepending ⇒ Object

Sets isPrepending state on the collection

Kind: inner property of redux-collections/actionCreators
Returns: Object - action

| Param | Type | Description | | --- | --- | --- | | collection | string | | | [map] | string | Name of parent map where collection lives | | [parentId] | Number | String | Key of parent map where collection lives |

redux-collections/actionCreators~collectionRemove ⇒ Object

Removes item from collection

Kind: inner property of redux-collections/actionCreators
Returns: Object - action

| Param | Type | Description | | --- | --- | --- | | collection | string | | | id | string | Element of array to remove | | [map] | string | Name of parent map where collection lives | | [parentId] | Number | String | Key of parent map where collection lives |

redux-collections/actionCreators~collectionReset ⇒ Object

Completely resets collection state with new items

Kind: inner property of redux-collections/actionCreators
Returns: Object - action

| Param | Type | Description | | --- | --- | --- | | collection | string | | | items | array | | | [map] | string | Name of parent map where collection lives | | [parentId] | Number | String | Key of parent map where collection lives |

redux-collections/actionCreators~collectionError ⇒ Object

Sets error on collection

Kind: inner property of redux-collections/actionCreators
Returns: Object - action

| Param | Type | Description | | --- | --- | --- | | collection | string | | | items | string | object | | | [map] | string | Name of parent map where collection lives | | [parentId] | Number | String | Key of parent map where collection lives |

redux-collections/actionCreators~collectionIsComplete ⇒ Object

Sets isComplete state on collection

Kind: inner property of redux-collections/actionCreators
Returns: Object - action

| Param | Type | Description | | --- | --- | --- | | collection | string | | | [map] | string | Name of parent map where collection lives | | [parentId] | Number | String | Key of parent map where collection lives |

redux-collections/actionCreators~mapAdd ⇒ Object

Merges given object with the map

Kind: inner property of redux-collections/actionCreators
Returns: Object - action

| Param | Type | Description | | --- | --- | --- | | map | string | Name of the map | | items | Object | Object to merge with the map |

redux-collections/actionCreators~mapRemove ⇒ Object

Removes object from map at given key

Kind: inner property of redux-collections/actionCreators
Returns: Object - action

| Param | Type | Description | | --- | --- | --- | | map | string | Name of the map | | id | Number | Key of object in map |

redux-collections/actionCreators~mapEdit ⇒ Object

Inject props with merging at given key in map

Kind: inner property of redux-collections/actionCreators
Returns: Object - action

| Param | Type | Description | | --- | --- | --- | | map | string | Name of the map | | id | Number | Key of object in map | | props | Object | Object with edited props |

redux-collections/actionCreators~mapIsEditing ⇒ Object

Sets isEditing state on object at given key in map

Kind: inner property of redux-collections/actionCreators
Returns: Object - action

| Param | Type | Description | | --- | --- | --- | | map | string | Name of the map | | id | Number | Key of object in map |

redux-collections/actionCreators~mapIsLoading ⇒ Object

Sets isLoading state on object at given key in map

Kind: inner property of redux-collections/actionCreators
Returns: Object - action

| Param | Type | Description | | --- | --- | --- | | map | string | Name of the map | | id | Number | Key of object in map |

redux-collections/actionCreators~mapError ⇒ Object

Sets error on object at given key in map

Kind: inner property of redux-collections/actionCreators
Returns: Object - action

| Param | Type | Description | | --- | --- | --- | | map | string | Name of the map | | id | Number | Key of object in map | | error | string | object | Key of object in map |

redux-collections/actionCreators~mapReset ⇒ Object

Completely resets map with given object

Kind: inner property of redux-collections/actionCreators
Returns: Object - action

| Param | Type | Description | | --- | --- | --- | | map | string | Name of the map | | items | Object | New map state |

redux-collections/reducers

redux-collections/reducers~collection(collection, [mixin]) ⇒ function

Creates a reducer for ordered collection

Kind: inner method of redux-collections/reducers
Returns: function - reducer

| Param | Type | Description | | --- | --- | --- | | collection | string | Name of collection | | [mixin] | function | Mixin reducer |

redux-collections/reducers~map(map, [names], [mixin]) ⇒ function

Creates a reducer for key: value map

Kind: inner method of redux-collections/reducers
Returns: function - reducer

| Param | Type | Description | | --- | --- | --- | | map | string | Name of map | | [names] | array | Array of names of child ordered collections (if present) | | [mixin] | function | Mixin reducer |

Contributing

npm run build, npm test, MIT, etc.