Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Type definitions for redux-injector
// Project: https://github.com/randallknutson/redux-injector
// Definitions by: Taylor Mitchell-St Joseph <http://taylormitchellstjoseph.co.uk>

import * as Redux from 'redux';

declare module 'redux-injector' {

interface createInjectStoreFn {
<S>(reducer: any, enhancer?: Redux.StoreEnhancer<S>): Redux.Store<S>;
<S>(reducer: any, preloadedState: S, enhancer?: Redux.StoreEnhancer<S>): Redux.Store<S>;
}

interface injectReducerFn {
(key: string, reducers: any, force?: boolean): void;
}

interface rejectReducerFn {
(key: string): void;
}

const createInjectStore: createInjectStoreFn;
const injectReducer: injectReducerFn;
const rejectReducer: rejectReducerFn;

}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"version": "0.1.0",
"description": "Allows dynamically injecting reducers into a redux store at runtime.",
"main": "lib/ReduxInjector.js",
"typescript": {
"definition": "index.d.ts"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "babel ./src --ignore=*.spec.js --out-dir ./lib --presets es2015,react,stage-2",
Expand Down
10 changes: 9 additions & 1 deletion src/ReduxInjector.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createStore, combineReducers } from 'redux';
import { set, has } from 'lodash';
import { set, has, unset } from 'lodash';

let store = {};
let combine = combineReducers;
Expand Down Expand Up @@ -53,3 +53,11 @@ export function injectReducer(key, reducer, force = false) {
set(store.injectedReducers, key, reducer);
store.replaceReducer(combineReducersRecurse(store.injectedReducers));
}

export function rejectReducer(key) {
// If key doesn't exist, do nothing
if (!has(store.injectedReducers, key)) return;

unset(store.injectedReducers, key);
store.replaceReducer(combineReducersRecurse(store.injectedReducers));
}