Skip to content

Commit

Permalink
Implement combinedReducers from scratch
Browse files Browse the repository at this point in the history
  • Loading branch information
zainsra7 committed Jan 23, 2022
1 parent ac1498d commit 00cae7a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/combinedReducers.js
@@ -0,0 +1,15 @@
export const combineReducers = reducers => {
// Reduce all keys for reducers from 'todos' and 'visibilityFilter'
return (state = {}, action) => {
return Object.keys(reducers).reduce(
(nextState, key) => {
nextState[key] = reducers[key](
state[key],
action
);
return nextState;
},
{} // iniital empty object
);
};
};
4 changes: 2 additions & 2 deletions src/index.js
@@ -1,6 +1,6 @@
import React from 'react';
import { combineReducers } from 'redux';
import {createStore} from './createStore';
import { combineReducers } from './combinedReducers';
import { createStore } from './createStore';
import ReactDOM from 'react-dom';
import './index.css';

Expand Down

0 comments on commit 00cae7a

Please sign in to comment.