Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

add defaultState from the original reducers to the namespaced ones #100

Merged
merged 5 commits into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion packages/redux-subspace/src/actions/processAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

import hasNamespace from '../actions/hasNamespace'
import isGlobal from '../actions/isGlobal'
import isReduxSpecific from '../actions/reduxSpecific'

const processAction = (namespace) => (action, callback, defaultValue) => {
if (!namespace || isGlobal(action)) {
if (!namespace || isGlobal(action) || isReduxSpecific(action)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be tempted to move this into the isGlobal check. Essentially we are saying that redux actions are always global actions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case should get a specific unit test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add tests a bit later

return callback(action)
} else if (hasNamespace(action, namespace)) {
return callback({...action, type: action.type.substring(namespace.length + 1)})
Expand Down
13 changes: 13 additions & 0 deletions packages/redux-subspace/src/actions/reduxSpecific.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Copyright 2017, IOOF Holdings Limited.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Copyright 2017, IOOF Holdings Limited.
* Copyright 2018, IOOF Holdings Limited.

Copy link
Contributor

@mpeyper mpeyper Dec 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github wont let me commit this (no permission to push the change, presumable to your fork), but yes.

* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

const REDUX_PREFIX = '@@redux/'

const reduxSpecific = (action) => action.type.startsWith(REDUX_PREFIX)

export default reduxSpecific

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add correct file ending

4 changes: 1 addition & 3 deletions packages/redux-subspace/src/reducers/namespaced.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export default (namespace) => {
return reducer(state, action)
}

const defaultState = reducer(state, action)

return actionProcessor(action, (transformedAction) => reducer(state, transformedAction), defaultState)
return actionProcessor(action, (transformedAction) => reducer(state, transformedAction), state)
}
}