• Stars
    star
    159
  • Rank 228,509 (Top 5 %)
  • Language
    JavaScript
  • Created about 8 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A collection of generic functions for writing redux reducers to operate on various data structures

Write better Redux code faster v0.0.5

Big changes from 0.0.4! API has been completely rewritten on top of ImmutableJS.

Codeship build status

A collection of generic functions on top of ImmutableJS and Redux Actions for simplifying your reducers. Declare your reducers and state as plain old javascript objects, but take advantage of Immutable guarantees and data structure traversal utilities.

Example reducer:

import { reducer, push, updateIn, removeIn } from 'redux-modifiers'

const reducer = reducer({
  'ADD_ITEM_TO_LIST': push,
  'UPDATE': updateIn,
  'ADD_NESTED_ITEM': (state, action)=>{
    let { selected, value } = action.payload; //Index of nested item (could be deeply nested, i.e. [0, 'key', 1])
    return state.updateIn(selected, item => item.push(value) ); //Using ImmutableJS API
  },
  'REMOVE': removeIn
}, []);

You can call toJS on any structure you get out of the reducer to convert it back to vanilla js, i.e. in a react component where you want to use spread operators, normal object accessors, etc. Anything you put in the reducer will automatically be converted to an ImmutableJS structure, which means you can do things like adding items to state from plain javascript objects without worrying about references sticking around.

Notes

FSA

redux-modifiers does expect that actions are dispatched as Flux Standard Actions. Essentially, this means every action looks like:

{
  type: YOUR_ACTION_TYPE,
  payload: YOUR_PAYLOAD
}

State and ImmutableJS

state is converted to an Immutable data structure, so you are free to use any ImmutableJS function you like on state. If you find you perform a particular option frequently, consider submitting a pull request and adding it to redux-modifiers!

Targeting specific parts of state

Use updateIn, to target specific parts of state, passing the update function the path that you want to update. Example state:

{
  foo: [
    {
      id: 1,
      name: 'Calvin'
    }
  ]
}

Example reducer function:

'UPDATE': updateIn

Example dispatch:

dispatch({selected: ['foo', 'name'], value: 'Calvin Froedge'});

API

push(state, action)

Payload can take any value, but you must call push on an array (List in ImmutableJS).

'ADD': push

updateIn(state, action)

Payload must include a selection path selected and a value or fn. State (or targeted key) will be replaced with value if value, or fn will be applied to the existing value.

Example payload:

{selected: [0, 'nested_array', 1], fn: value => value * 2}

removeIn(state, action)

Payload must include a selection path. Example payload:

[0, 'nested_array', 1]

More Repositories

1

codeigniter-payments

Spark for Uniform Payments in CodeIgniter, based on PHP-Payments. Supports 12+ payment gateways.
PHP
245
star
2

PHP-Payments

A uniform payments interface for PHP
PHP
122
star
3

octobadge-github-badge

OctoBadge - Unofficial Github Badge for Display Data About Your Github History
JavaScript
78
star
4

codeigniter-oauth

Spark for Integrating with Multiple OAuth Providers
PHP
33
star
5

react-redux-auth0

React / Redux / Auth0
JavaScript
23
star
6

CodeIgniter-Payments-Library

Library for Supporting Multiple Payment Systems with CodeIgniter Reactor
PHP
20
star
7

node-jspdf

jsPDF on the server.
JavaScript
14
star
8

react-redux-workbench

A starting point for creating React components, including babel, webpack, mocha tests, redux, hot reloads, etc.
JavaScript
14
star
9

fuelphp_starter

A starting point for FuelApps.
PHP
12
star
10

react-component-helpers

Awesome helpers for removing the boilerplate from your component state, props, and interactions.
JavaScript
12
star
11

FuelPay

Fuel port of PHP-Payments
PHP
9
star
12

FuelPHP---CampaignMonitor-API-Package

FuelPHP Package for Working With CampaignMonitor API
PHP
7
star
13

Hydro---Lang-File-2-HTML-Parser-for-FuelPHP

Parse a language array into HTML content in FuelPHP framework.
PHP
7
star
14

Aweber-API-NodeJS-Library

OAuth 1.0 implementation and API client for Aweber on NodeJS
JavaScript
6
star
15

BreezyDo-CodeIgniter-PHP-Todo-Manager

PHP / CodeIgniter based task manager.
PHP
5
star
16

docker-node-forever-express-postgres-example

Example app to be run by github.com/calvinfroedge/node-docker-compose-devenv
JavaScript
5
star
17

react-bootstrap-quick-modal

React / Bootstrap modals with fewer keystrokes
JavaScript
3
star
18

Codeigniter-Aktive-Merchant

Implementation of Aktive Merchant by Andreas Kollaros (PHP)
PHP
3
star
19

node-docker-compose-devenv

A simple dev environment using docker, node, postgres, and docker-compose
3
star
20

HackNashville

JavaScript
3
star
21

Factorials

Factorials using different styles and languages
3
star
22

legolas

Elegant OAuth on top of Express, Passport, Sessions, Sockets
JavaScript
3
star
23

react-redux-app-header

App header with Auth0 login /logout for react / redux apps
JavaScript
3
star
24

Singletons

Simple Singleton implementation in multiple languages, achieving multiple ends
PHP
2
star
25

google-apps-engine-rest-api-starter

A starting point for JSON REST APIs using Google App Engine
Python
2
star
26

EzFormz

PHP Form Generation & Validation Library
PHP
1
star
27

react-boot

Opinionated starting point for react apps
JavaScript
1
star
28

file-upload-client-component

A filepicker component for loading files from client to browser
JavaScript
1
star
29

scaffold

Scaffold
PHP
1
star
30

webpack-express-react-redux-kitchen-sink

Everything you'll ever need for a React app
JavaScript
1
star
31

miniModal

Lightweight JavaScript modal window plugin for jQuery.
JavaScript
1
star
32

grunt-if-modified

Conditionally run grunt tasks only if a source directory has been changed since the last time the task was run
JavaScript
1
star
33

namespaced-constants

Use consts to declare namespaced constants with some sugar.
JavaScript
1
star
34

ColorPickerComponent

A framework agnostic color picker component
JavaScript
1
star