-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Drop enhancer API in favor of separate middlewares+reducer
BREAKING CHANGE: makeMidiEnhancer has been removed. It became increasingly difficult to reason about its correctness with respect to other enhancers and particularly user-specified middleware. The new API is a little more verbose but allows the user to place MIDI I/O explicitly in the middleware chain as well as explicitly mount the required reducer into their state tree. Tests, documentation and the bare-input example are up-to-date.
- Loading branch information
Showing
8 changed files
with
150 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,22 @@ | ||
import { createStore, applyMiddleware, compose } from 'redux'; | ||
import createLogger from 'redux-logger'; | ||
import { makeMidiEnhancer } from '../../src'; | ||
import setup, {reducer as midiReducer, RECEIVE_MIDI_MESSAGE} from '../../src'; | ||
import {createStore, applyMiddleware, compose, combineReducers} from 'redux'; | ||
|
||
const logger = createLogger(); | ||
export default function configureStore () { | ||
const rootReducer = combineReducers({ | ||
midi: midiReducer, | ||
midiMessages: (state, action) => { | ||
if (!state) state = []; | ||
if (action.type === RECEIVE_MIDI_MESSAGE) { | ||
state = [action.payload, ...state]; | ||
} | ||
return state; | ||
} | ||
}); | ||
|
||
export default function configureStore (initialState, reducer) { | ||
let actions = []; | ||
const {inputMiddleware, outputMiddleware} = setup({midiOptions: {sysex: true}}); | ||
|
||
function collector ({getState}) { | ||
return (next) => (action) => { | ||
actions.push(action); | ||
return next(action); | ||
}; | ||
} | ||
const middleware = [collector, logger]; | ||
|
||
const store = createStore(reducer || (state => state), initialState, compose( | ||
makeMidiEnhancer({midiOptions: {sysex: true}}), | ||
applyMiddleware(...middleware), | ||
return createStore(rootReducer, compose( | ||
applyMiddleware(inputMiddleware, outputMiddleware), | ||
global.devToolsExtension ? global.devToolsExtension() : f => f | ||
)); | ||
|
||
return store; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
export default function observeStore (store, select, onChange) { | ||
export default function observeStore ({getState, subscribe}, select, onChange) { | ||
let currentState; | ||
|
||
function handleChange () { | ||
const nextState = select(store.getState()); | ||
const nextState = select(getState()); | ||
if (nextState !== currentState) { | ||
const prevState = currentState; | ||
currentState = nextState; | ||
onChange(currentState, prevState); | ||
} | ||
} | ||
|
||
let unsubscribe = store.subscribe(handleChange); | ||
let unsubscribe = subscribe(handleChange); | ||
handleChange(); | ||
return unsubscribe; | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.