Skip to content

Commit

Permalink
reduce mount complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Dashney committed Jun 27, 2018
1 parent 71821d0 commit acaf5ea
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 99 deletions.
46 changes: 46 additions & 0 deletions src/mount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import get from 'lodash.get'
import warning from 'warning'
import createActions from './create-actions'
import mountActions from './mount-actions'

export default function mount (pathToState, logic) {
warning(true, 'redux-modular mount() is deprecated')
validateArgs(...arguments)
return mountLogic(pathToState, logic)
}

function validateArgs (pathToState, logic) {
if (!logic) {
throw new Error('logic must be passed to mount')
}
}

function mountLogic (pathToState, logic) {
const result = {}

if (logic.actions) {
result.actions = createAndMountActions(pathToState, logic.actions)
}

if (logic.actions && logic.reducer) {
result.reducer = logic.reducer(result.actions)
}

if (logic.selectors) {
createSelectors(pathToState, logic.selectors)
}

return result
}

function createAndMountActions (pathToState, actions) {
return mountActions(pathToState, createActions(actions))
}

function createSelectors (pathToState, selectors) {
const localStateSelector = pathToState
? state => get(state, pathToState)
: state => state

return selectors(localStateSelector)
}
18 changes: 0 additions & 18 deletions src/mount/globalize-actions.js

This file was deleted.

35 changes: 0 additions & 35 deletions src/mount/index.js

This file was deleted.

4 changes: 2 additions & 2 deletions test/mount/mount.test.js → test/mount.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-env jest */

import { combineReducers } from 'redux'
import createReducer from '../../src/create-reducer'
import mount from '../../src/mount'
import createReducer from '../src/create-reducer'
import mount from '../src/mount'

it('mounts redux path to action types', () => {
const logic = mount('path.to.module', {
Expand Down
44 changes: 0 additions & 44 deletions test/mount/globalize-actions.test.js

This file was deleted.

0 comments on commit acaf5ea

Please sign in to comment.