Skip to content

Commit 982ab86

Browse files
committed
Merge pull request #668 from rackt/remove-get-reducer
Remove getReducer() from Store API
2 parents 44a0dc6 + 5144bbe commit 982ab86

File tree

5 files changed

+4
-41
lines changed

5 files changed

+4
-41
lines changed

docs/Glossary.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ type Store = {
9797
dispatch: Dispatch;
9898
getState: () => State;
9999
subscribe: (listener: () => void) => () => void;
100-
getReducer: () => Reducer;
101100
replaceReducer: (reducer: Reducer) => void;
102101
};
103102
```
@@ -108,7 +107,7 @@ There should only be a single store in a Redux app, as the composition happens o
108107
- [`dispatch(action)`](api/Store.md#dispatch) is the base dispatch function described above.
109108
- [`getState()`](api/Store.md#getState) returns the current state of the store.
110109
- [`subscribe(listener)`](api/Store.md#subscribe) registers a function to be called on state changes.
111-
- [`getReducer()`](api/Store.md#getReducer) and [`replaceReducer(nextReducer)`](api/Store.md#replaceReducer) can be used to implement hot reloading and code splitting. Most likely you won’t use them.
110+
- [`replaceReducer(nextReducer)`](api/Store.md#replaceReducer) can be used to implement hot reloading and code splitting. Most likely you won’t use it.
112111

113112
See the complete [store API reference](api/Store.md#dispatch) for more details.
114113

docs/api/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ This section documents the complete Redux API. Keep in mind that Redux is only c
1818
* [getState()](Store.md#getState)
1919
* [dispatch(action)](Store.md#dispatch)
2020
* [subscribe(listener)](Store.md#subscribe)
21-
* [getReducer()](Store.md#getReducer)
2221
* [replaceReducer(nextReducer)](Store.md#replaceReducer)
2322

2423
### Importing

docs/api/Store.md

-18
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ To create it, pass your root [reducing function](../Glossary.md#reducer) to [`cr
1515
- [`getState()`](#getState)
1616
- [`dispatch(action)`](#dispatch)
1717
- [`subscribe(listener)`](#subscribe)
18-
- [`getReducer()`](#getReducer)
1918
- [`replaceReducer(nextReducer)`](#replaceReducer)
2019

2120
## Store Methods
@@ -118,23 +117,6 @@ handleChange();
118117

119118
<hr>
120119

121-
### <a id='getReducer'></a>[`getReducer()`](#getReducer)
122-
123-
>##### Deprecated
124-
125-
>This API has been [deprecated](https://github.com/rackt/redux/issues/350).
126-
>It will be removed when we find a better solution for this problem.
127-
128-
Returns the reducer currently used by the store to calculate the state.
129-
130-
It is an advanced API. You might only need this if you implement a hot reloading mechanism for Redux.
131-
132-
#### Returns
133-
134-
(*Function*): The store’s current reducer.
135-
136-
<hr>
137-
138120
### <a id='replaceReducer'></a>[`replaceReducer(nextReducer)`](#replaceReducer)
139121

140122
>##### Deprecated

src/createStore.js

-14
Original file line numberDiff line numberDiff line change
@@ -109,18 +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-
124112
/**
125113
* Replaces the reducer currently used by the store to calculate the state.
126114
*
@@ -136,7 +124,6 @@ export default function createStore(reducer, initialState) {
136124
dispatch({ type: ActionTypes.INIT });
137125
}
138126

139-
140127
// When a store is created, an "INIT" action is dispatched so that every
141128
// reducer returns their initial state. This effectively populates
142129
// the initial state tree.
@@ -146,7 +133,6 @@ export default function createStore(reducer, initialState) {
146133
dispatch,
147134
subscribe,
148135
getState,
149-
getReducer,
150136
replaceReducer
151137
};
152138
}

test/createStore.spec.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -8,11 +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(4);
1212
expect(methods).toContain('subscribe');
1313
expect(methods).toContain('dispatch');
1414
expect(methods).toContain('getState');
15-
expect(methods).toContain('getReducer');
1615
expect(methods).toContain('replaceReducer');
1716
});
1817

@@ -106,8 +105,7 @@ describe('createStore', () => {
106105
text: 'World'
107106
}]);
108107

109-
let nextStore = createStore(reducers.todosReverse);
110-
store.replaceReducer(nextStore.getReducer());
108+
store.replaceReducer(reducers.todosReverse);
111109
expect(store.getState()).toEqual([{
112110
id: 1,
113111
text: 'Hello'
@@ -128,8 +126,7 @@ describe('createStore', () => {
128126
text: 'World'
129127
}]);
130128

131-
nextStore = createStore(reducers.todos);
132-
store.replaceReducer(nextStore.getReducer());
129+
store.replaceReducer(reducers.todos);
133130
expect(store.getState()).toEqual([{
134131
id: 3,
135132
text: 'Perhaps'

0 commit comments

Comments
 (0)