• Stars
    star
    686
  • Rank 63,951 (Top 2 %)
  • Language
    JavaScript
  • License
    BSD 3-Clause "New...
  • Created almost 9 years ago
  • Updated almost 5 years ago

Reviews

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

Repository Details

Redux Immutable facilities.

redux-immutablejs

Redux & Immutable integration

This is a small library that aims to provide integration tools between Redux & ImmutableJs that fully conforms Redux actions & reducers standards.

  1. An alternative to combineReducers that supports ImmutableJs for store initial state.
  2. An optional handler map reducer creator with immutable support.

Setup

Initial State

Using combineReducers it is possible to provide createStore with initial state using Immutable Iterable type, i.e:

import { createStore } from 'redux';
import { combineReducers } from 'redux-immutablejs';

import Immutable from 'immutable';
import * as reducers from './reducers';

const reducer = combineReducers(reducers);
const state = Immutable.fromJS({});

const store = reducer(state);
export default createStore(reducer, store);

Immutable Handler Map reducer creator

Using createReducer is an optional function that creates a reducer from a collection of handlers. In addition to getting rid of the switch statement, it also provides the following benefits:

  1. If the given initialState type is mutated, it will get converted to an immutable type.
  2. An error is produced in case a reducer handler returns a mutated state (not recommended but this behavior can be disabled)
import { createReducer } from 'redux-immutablejs'
const initialState = Immutable.fromJS({ isAuth: false })

/**
 * Reducer domain that handles authentication & authorization.
 **/
export default createReducer(initialState, {
  [LOGIN]: (state, action) => state.merge({
    isAuth: true,
    token: action.payload.token
  }),

  [LOGOUT]: (domain) => domain.merge({
    isAuth: false,
    current_identity: {},
    token: undefined
  })
})

If you want to specify the Immutable type to be used for implicit conversion, pass an constructor function at the end:

export default createReducer([], {
  [ADD_STUFF]: (state, { stuff }) => state.add(stuff)
}, true, ::Immutable.OrderedSet);

Please note that this is optional and combineReducers should work just fine if you prefer the old switch way.

FAQ

How this library is different from 'redux-immutable' ?

This library doesn't dictate any specific reducer structure. While redux-immutable focuses on CRC, this library provides some conversion middlewares from FSA to CCA and vise versa. If you feel like going with Redux's vanilla is the right approach, then consider using our library.

More Repositories

1

ember-forms

Smart, Intuitive forms for Ember.js styled with Bootstrap, Multi layouts and Validation support.
JavaScript
218
star
2

ember-components

Rich components for Ember.js framework.
JavaScript
184
star
3

re-notif

Redux & React based Notifications center.
JavaScript
148
star
4

antiquity

Antiquity - A versioned graph extension.
Java
37
star
5

ember-idx-tree

An ambitious Tree Component for Ember.js
JavaScript
27
star
6

ember-idx-wysiwyg

Ambitious WYSIWYG (What you see is what you get) html editor written purely in Ember.js
JavaScript
18
star
7

ember-idx-modal

Ember Indexia Modal
JavaScript
17
star
8

ember-idx-tabs

Ambitious tabs component.
JavaScript
17
star
9

ember-idx-button

An ambitious button with async & styling support for Ember.js
JavaScript
11
star
10

hapi-elastic

Hapi Plugin for Elastic Search
JavaScript
8
star
11

ember-idx-tour

Ambitious Tour for Ember.js
JavaScript
7
star
12

ember-idx-accordion

Ambitious accordion component.
JavaScript
7
star
13

ember-cli-components

Ember Components as ember-cli addon
JavaScript
6
star
14

ember-idx-charts

Ambitious charts for Ember.js
JavaScript
6
star
15

ember-idx-list

Ambitious list of items with selection & states.
JavaScript
3
star
16

gulp-release-flows

Gulp Release flow plugin
JavaScript
2
star
17

indexiatech.github.io

Web site
JavaScript
2
star
18

ember-cli-pegjs

PegJs Ember CLI addon
JavaScript
2
star
19

hapier

A happier way to use Hapi.
JavaScript
2
star
20

ember-idx-utils

A set of utilities for Ember.js
JavaScript
2
star
21

ember-idx-gmaps

Ambitious Google Maps Component for Ember.js
JavaScript
1
star
22

react-helmet

JavaScript
1
star