Created
October 30, 2018 15:31
-
-
Save Nauthiz-Jera/4a76a4c28a2a2d4058b2808cc29590a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { comp, into, map, filter } from 'transducers-js' | |
/* eslint-disable no-return-assign */ | |
// setReducer :: (a -> {a}) -> ({b} -> {a}) | |
// add reducers that are missing from the store | |
const setReducer = injectedReducers => ({key, reducer}) => injectedReducers[key] = reducer | |
/* eslint-enable */ | |
// hasReducer :: (a -> {a}) -> ({b} -> bool) | |
// returns a boolean based if the reducer to inject exists already or not | |
const hasReducer = injectedReducers => ({key, reducer}) => | |
Reflect.has(injectedReducers, key) && injectedReducers[key] === reducer | |
// filterExistingReducersAddNewReducers :: a -> b | |
const filterExistingReducersAddNewReducers = injectReducers => comp(map(setReducer(injectReducers)), filter(hasReducer(injectReducers))) | |
// setupNewReducer ({a}, [{b}]) -> {a} | |
// add new reducers if they do do not already exist in the store | |
export const setupNewReducers = (injectedReducers, collection) => into(injectedReducers, filterExistingReducersAddNewReducers(injectedReducers), collection) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment