Skip to content

Commit 22a20f0

Browse files
committed
Remove getReducer and replaceReducer
1 parent 8272831 commit 22a20f0

File tree

2 files changed

+2
-97
lines changed

2 files changed

+2
-97
lines changed

src/createStore.js

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -109,34 +109,6 @@ export default function createStore(reducer, initialState) {
109109
return action;
110110
}
111111

112-
/**
113-
* Returns the reducer currently used by the store to calculate the state.
114-
*
115-
* It is likely that you will only need this function if you implement a hot
116-
* reloading mechanism for Redux.
117-
*
118-
* @returns {Function} The reducer used by the current store.
119-
*/
120-
function getReducer() {
121-
return currentReducer;
122-
}
123-
124-
/**
125-
* Replaces the reducer currently used by the store to calculate the state.
126-
*
127-
* You might need this if your app implements code splitting and you want to
128-
* load some of the reducers dynamically. You might also need this if you
129-
* implement a hot reloading mechanism for Redux.
130-
*
131-
* @param {Function} nextReducer The reducer for the store to use instead.
132-
* @returns {void}
133-
*/
134-
function replaceReducer(nextReducer) {
135-
currentReducer = nextReducer;
136-
dispatch({ type: ActionTypes.INIT });
137-
}
138-
139-
140112
// When a store is created, an "INIT" action is dispatched so that every
141113
// reducer returns their initial state. This effectively populates
142114
// the initial state tree.
@@ -145,8 +117,6 @@ export default function createStore(reducer, initialState) {
145117
return {
146118
dispatch,
147119
subscribe,
148-
getState,
149-
getReducer,
150-
replaceReducer
120+
getState
151121
};
152122
}

test/createStore.spec.js

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ describe('createStore', () => {
88
const store = createStore(combineReducers(reducers));
99
const methods = Object.keys(store);
1010

11-
expect(methods.length).toBe(5);
11+
expect(methods.length).toBe(3);
1212
expect(methods).toContain('subscribe');
1313
expect(methods).toContain('dispatch');
1414
expect(methods).toContain('getState');
15-
expect(methods).toContain('getReducer');
16-
expect(methods).toContain('replaceReducer');
1715
});
1816

1917
it('should require a reducer function', () => {
@@ -94,69 +92,6 @@ describe('createStore', () => {
9492
}]);
9593
});
9694

97-
it('should preserve the state when replacing a reducer', () => {
98-
const store = createStore(reducers.todos);
99-
store.dispatch(addTodo('Hello'));
100-
store.dispatch(addTodo('World'));
101-
expect(store.getState()).toEqual([{
102-
id: 1,
103-
text: 'Hello'
104-
}, {
105-
id: 2,
106-
text: 'World'
107-
}]);
108-
109-
let nextStore = createStore(reducers.todosReverse);
110-
store.replaceReducer(nextStore.getReducer());
111-
expect(store.getState()).toEqual([{
112-
id: 1,
113-
text: 'Hello'
114-
}, {
115-
id: 2,
116-
text: 'World'
117-
}]);
118-
119-
store.dispatch(addTodo('Perhaps'));
120-
expect(store.getState()).toEqual([{
121-
id: 3,
122-
text: 'Perhaps'
123-
}, {
124-
id: 1,
125-
text: 'Hello'
126-
}, {
127-
id: 2,
128-
text: 'World'
129-
}]);
130-
131-
nextStore = createStore(reducers.todos);
132-
store.replaceReducer(nextStore.getReducer());
133-
expect(store.getState()).toEqual([{
134-
id: 3,
135-
text: 'Perhaps'
136-
}, {
137-
id: 1,
138-
text: 'Hello'
139-
}, {
140-
id: 2,
141-
text: 'World'
142-
}]);
143-
144-
store.dispatch(addTodo('Surely'));
145-
expect(store.getState()).toEqual([{
146-
id: 3,
147-
text: 'Perhaps'
148-
}, {
149-
id: 1,
150-
text: 'Hello'
151-
}, {
152-
id: 2,
153-
text: 'World'
154-
}, {
155-
id: 4,
156-
text: 'Surely'
157-
}]);
158-
});
159-
16095
it('should support multiple subscriptions', () => {
16196
const store = createStore(reducers.todos);
16297
const listenerA = expect.createSpy(() => {});

0 commit comments

Comments
 (0)