Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redux-loop-immutable

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-loop-immutable

ImmutableJS Extensions for Redux Loop

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

redux-loop-immutable

ImmutableJS helpers for use with Redux Loop

Installation

Redux Loop Immutable requires redux-loop 4.1.0 or higher

npm install --save redux-loop-immutable

API

combineReducers(reducersMap)

This is simply an ImmutableJS-optimized version of the combineReducers provided by core redux-loop. Instead of the default state being a plain object, it is an Immutable.Map instance.

Arguments
  • reducersMap: Object<string, ReducerFunction> – a plain object map of keys to nested reducers, just like the combineReducers you would find in Redux itself.
Examples
import { combineReducers } from 'redux-loop-immutable';
import reducerWithSideEffects from './reducer-with-side-effects';
import plainReducer from './plain-reducer';

export default combineReducers({
  withEffects: reducerWithSideEffects,
  plain: plainReducer
});

mergeChildReducers(parentResult, action, childMap)

This is an ImmutableJS-optimized version of the mergeChildRedcuers provided by core redux-loop. Like that version of mergeChildReducers, it is a more generalized version of combineReducers that allows you to nest reducers underneath a common parent that has functionality of its own (rather than restricting the parent to simply passing actions to its children like combineReducers does)

  • parentResult: Immutable.Map | loop(Immutable.Map, Cmd) – The result from the parent reducer before any child results have been applied.
  • action: Action – a redux action
  • childMap: Object<string, ReducerFunction> – a plain object map of keys to nested reducers, similar to the map in combineReducers. However, a key can be given a value of null to have it removed from the state.
Examples
import { mergeChildReducers } from 'redux-loop-immutable';
import {getModel, isLoop} from 'redux-loop';
import { fromJS } from 'immutable'
import pageReducerMap from './page-reducers';

// a simple reducer that keeps track of your current location and nests the correct
//child reducer for that location at state.data

const initialState = fromJS({
   location: 'index'
   //data will be filled in with the result of the child reducer
});

function parentReducer(state = initialState, action){
  if(action.type !== 'LOCATION_CHANGE')
     return state;
     
  return state.set('location', action.newLocation);
}

export default function reducer(state, action){
  const parentResult = parentReducer(state, action);
  
  let location;
  if(isLoop(parentResult))
    location = getModel(parentResult).get('location');
  else
    location = parentResult.get('location');
   
  const childMap = {data: pageReducerMap[location]};
  
  return mergeChildReducers(parentResult, action, childMap);
}

Support

Potential bugs, generally discussion, and proposals or RFCs should be submitted as issues to this repo, we'll do our best to address them quickly. We use this library as well and want it to be the best it can! For questions about using the library, submit questions on StackOverflow with the redux-loop tag.

Contributing

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. Multiple language translations are available at contributor-covenant.org

Keywords

FAQs

Package last updated on 16 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc