Skip to content

Commit 109f158

Browse files
authored
v0.5.8
* fix(orderedReducer): `CLEAR_DATA` action correctly clears `ordered` state for actions dispatched without meta - #114 * fix(tests): update orderedReducer tests to include case of `CLEAR_DATA` action dispatched without `meta` - #114 * fix(typings): make `otherConfig` optional for `reduxFirestore` (store enhancer) in typings - @am17torres
2 parents 9e70eca + 739bde3 commit 109f158

File tree

5 files changed

+12
-18
lines changed

5 files changed

+12
-18
lines changed

index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ export const constants: {
8585
* A redux store enhancer that adds store.firebase (passed to React component
8686
* context through react-redux's <Provider>).
8787
*/
88-
export function reduxFirestore(firebaseInstance: object, otherConfig: object): any;
88+
export function reduxFirestore(firebaseInstance: object, otherConfig?: object): any;
8989

9090
/**
9191
* Get extended firestore instance (attached to store.firestore)
9292
*/
93-
export function getFirestore(firebaseInstance: object, otherConfig: object): any;
93+
export function getFirestore(firebaseInstance: object, otherConfig?: object): any;
9494

9595
/**
9696
* A redux store reducer for Firestore state

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "redux-firestore",
3-
"version": "0.5.7",
3+
"version": "0.5.8",
44
"description": "Redux bindings for Firestore.",
55
"main": "lib/index.js",
66
"module": "es/index.js",

src/reducers/orderedReducer.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,8 @@ const orderedCollectionReducer = createReducer(undefined, actionHandlers);
230230
* @return {Object} Ordered state after reduction
231231
*/
232232
export default function orderedReducer(state = {}, action) {
233-
// Return state if action is malformed (i.e. no type, or valid meta)
234-
if (
235-
!action.type ||
236-
!action.meta ||
237-
(!action.meta.storeAs && !action.meta.collection)
238-
) {
233+
// Return state if action is malformed (i.e. no type)
234+
if (!action.type) {
239235
return state;
240236
}
241237

@@ -253,6 +249,11 @@ export default function orderedReducer(state = {}, action) {
253249
return state;
254250
}
255251

252+
// Return state if action does not contain valid meta
253+
if (!action.meta || (!action.meta.storeAs && !action.meta.collection)) {
254+
return state;
255+
}
256+
256257
const storeUnderKey = action.meta.storeAs || action.meta.collection;
257258
const collectionStateSlice = get(state, storeUnderKey);
258259
return {

test/unit/reducers/orderedReducer.spec.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -587,17 +587,14 @@ describe('orderedReducer', () => {
587587
it('removes all data from state', () => {
588588
action = {
589589
type: actionTypes.CLEAR_DATA,
590-
meta: { collection: 'testing' }, // meta is required to trigger ordered reducer
591590
};
592-
state = {};
593-
expect(orderedReducer(state, action)).to.be.empty;
591+
state = { some: [{ id: 'thing' }] };
594592
expect(orderedReducer(state, action)).to.be.empty;
595593
});
596594

597595
it('sets a new reference when clearing', () => {
598596
action = {
599597
type: actionTypes.CLEAR_DATA,
600-
meta: { collection: 'testing' }, // meta is required to trigger ordered reducer
601598
};
602599
state = {};
603600
expect(orderedReducer(state, action)).to.not.equal(state);
@@ -606,9 +603,7 @@ describe('orderedReducer', () => {
606603
describe('preserve parameter', () => {
607604
it('array saves keys from state', () => {
608605
action = {
609-
meta: { collection: 'testing' }, // meta is required to trigger ordered reducer
610606
type: actionTypes.CLEAR_DATA,
611-
payload: {},
612607
preserve: { ordered: ['some'] },
613608
};
614609
state = { some: 'value' };
@@ -617,9 +612,7 @@ describe('orderedReducer', () => {
617612

618613
it('function returns state to save', () => {
619614
action = {
620-
meta: { collection: 'testing' }, // meta is required to trigger ordered reducer
621615
type: actionTypes.CLEAR_DATA,
622-
payload: {},
623616
preserve: { ordered: currentState => currentState },
624617
};
625618
state = { some: 'value' };

0 commit comments

Comments
 (0)