Created
October 2, 2016 21:38
-
-
Save vojtatranta/511920e758a2d454b6174975ac0cef4a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var currentReducer = reducer | |
var currentState = preloadedState | |
var currentListeners = [] | |
var nextListeners = currentListeners | |
var isDispatching = false | |
function dispatch(action) { | |
if (!isPlainObject(action)) { | |
throw new Error( | |
'Actions must be plain objects. ' + | |
'Use custom middleware for async actions.' | |
) | |
} | |
if (typeof action.type === 'undefined') { | |
throw new Error( | |
'Actions may not have an undefined "type" property. ' + | |
'Have you misspelled a constant?' | |
) | |
} | |
if (isDispatching) { | |
throw new Error('Reducers may not dispatch actions.') | |
} | |
try { | |
isDispatching = true | |
currentState = currentReducer(currentState, action) | |
} finally { | |
isDispatching = false | |
} | |
var listeners = currentListeners = nextListeners | |
for (var i = 0; i < listeners.length; i++) { | |
var listener = listeners[i] | |
listener() | |
} | |
return action | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment