Permalink
Browse files

Add prettier formatting to src and test (#2676)

  • Loading branch information...
adityavohra7 authored and timdorr committed Dec 11, 2017
1 parent dddab5d commit 87071fd4ab71acc4fdd8b3db37d2d7ff08b724a3
View
@@ -5,7 +5,7 @@ module.exports = {
{
files: 'test/**/*.js',
env: {
jest: true,
jest: true,
},
},
],
View
@@ -0,0 +1,4 @@
{
"semi": false,
"singleQuote": true
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -14,6 +14,8 @@
],
"scripts": {
"clean": "rimraf lib dist es coverage",
"format": "prettier --write '{src,test}/**/*.js'",
"format:check": "prettier --list-different '{src,test}/**/*.js'",
"lint": "eslint src test build",
"pretest": "npm run build:commonjs",
"test": "cross-env BABEL_ENV=commonjs jest",
@@ -24,7 +26,7 @@
"build:umd": "cross-env BABEL_ENV=es NODE_ENV=development rollup -c -o dist/redux.js",
"build:umd:min": "cross-env BABEL_ENV=es NODE_ENV=production rollup -c -o dist/redux.min.js",
"build": "npm run build:commonjs && npm run build:es && npm run build:umd && npm run build:umd:min",
"prepare": "npm run clean && npm run lint && npm test && npm run build",
"prepare": "npm run clean && npm run format:check && npm run lint && npm test && npm run build",
"examples:lint": "eslint examples",
"examples:test": "cross-env CI=true babel-node examples/testAll.js",
"docs:clean": "rimraf _book",
@@ -82,6 +84,7 @@
"gitbook-cli": "^2.3.2",
"glob": "^7.1.1",
"jest": "^21.2.1",
"prettier": "1.8.2",
"rimraf": "^2.6.2",
"rollup": "^0.51.8",
"rollup-plugin-babel": "^3.0.2",
View
@@ -17,12 +17,12 @@ import compose from './compose'
* @returns {Function} A store enhancer applying the middleware.
*/
export default function applyMiddleware(...middlewares) {
return (createStore) => (...args) => {
return createStore => (...args) => {
const store = createStore(...args)
let dispatch = () => {
throw new Error(
`Dispatching while constructing your middleware is not allowed. ` +
`Other middleware would not be applied to this dispatch.`
`Other middleware would not be applied to this dispatch.`
)
}
let chain = []
View
@@ -1,5 +1,7 @@
function bindActionCreator(actionCreator, dispatch) {
return function() { return dispatch(actionCreator.apply(this, arguments)) }
return function() {
return dispatch(actionCreator.apply(this, arguments))
}
}
/**
@@ -30,8 +32,10 @@ export default function bindActionCreators(actionCreators, dispatch) {
if (typeof actionCreators !== 'object' || actionCreators === null) {
throw new Error(
`bindActionCreators expected an object or a function, instead received ${actionCreators === null ? 'null' : typeof actionCreators}. ` +
`Did you write "import ActionCreators from" instead of "import * as ActionCreators from"?`
`bindActionCreators expected an object or a function, instead received ${
actionCreators === null ? 'null' : typeof actionCreators
}. ` +
`Did you write "import ActionCreators from" instead of "import * as ActionCreators from"?`
)
}
View
@@ -4,7 +4,8 @@ import isPlainObject from './utils/isPlainObject'
function getUndefinedStateErrorMessage(key, action) {
const actionType = action && action.type
const actionDescription = (actionType && `action "${String(actionType)}"`) || 'an action'
const actionDescription =
(actionType && `action "${String(actionType)}"`) || 'an action'
return (
`Given ${actionDescription}, reducer "${key}" returned undefined. ` +
@@ -13,11 +14,17 @@ function getUndefinedStateErrorMessage(key, action) {
)
}
function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, unexpectedKeyCache) {
function getUnexpectedStateShapeWarningMessage(
inputState,
reducers,
action,
unexpectedKeyCache
) {
const reducerKeys = Object.keys(reducers)
const argumentName = action && action.type === ActionTypes.INIT ?
'preloadedState argument passed to createStore' :
'previous state received by the reducer'
const argumentName =
action && action.type === ActionTypes.INIT
? 'preloadedState argument passed to createStore'
: 'previous state received by the reducer'
if (reducerKeys.length === 0) {
return (
@@ -29,15 +36,14 @@ function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, une
if (!isPlainObject(inputState)) {
return (
`The ${argumentName} has unexpected type of "` +
({}).toString.call(inputState).match(/\s([a-z|A-Z]+)/)[1] +
{}.toString.call(inputState).match(/\s([a-z|A-Z]+)/)[1] +
`". Expected argument to be an object with the following ` +
`keys: "${reducerKeys.join('", "')}"`
)
}
const unexpectedKeys = Object.keys(inputState).filter(key =>
!reducers.hasOwnProperty(key) &&
!unexpectedKeyCache[key]
const unexpectedKeys = Object.keys(inputState).filter(
key => !reducers.hasOwnProperty(key) && !unexpectedKeyCache[key]
)
unexpectedKeys.forEach(key => {
@@ -64,22 +70,30 @@ function assertReducerShape(reducers) {
if (typeof initialState === 'undefined') {
throw new Error(
`Reducer "${key}" returned undefined during initialization. ` +
`If the state passed to the reducer is undefined, you must ` +
`explicitly return the initial state. The initial state may ` +
`not be undefined. If you don't want to set a value for this reducer, ` +
`you can use null instead of undefined.`
`If the state passed to the reducer is undefined, you must ` +
`explicitly return the initial state. The initial state may ` +
`not be undefined. If you don't want to set a value for this reducer, ` +
`you can use null instead of undefined.`
)
}
const type = '@@redux/PROBE_UNKNOWN_ACTION_' + Math.random().toString(36).substring(7).split('').join('.')
const type =
'@@redux/PROBE_UNKNOWN_ACTION_' +
Math.random()
.toString(36)
.substring(7)
.split('')
.join('.')
if (typeof reducer(undefined, { type }) === 'undefined') {
throw new Error(
`Reducer "${key}" returned undefined when probed with a random type. ` +
`Don't try to handle ${ActionTypes.INIT} or other actions in "redux/*" ` +
`namespace. They are considered private. Instead, you must return the ` +
`current state for any unknown actions, unless it is undefined, ` +
`in which case you must return the initial state, regardless of the ` +
`action type. The initial state may not be undefined, but can be null.`
`Don't try to handle ${
ActionTypes.INIT
} or other actions in "redux/*" ` +
`namespace. They are considered private. Instead, you must return the ` +
`current state for any unknown actions, unless it is undefined, ` +
`in which case you must return the initial state, regardless of the ` +
`action type. The initial state may not be undefined, but can be null.`
)
}
})
@@ -137,7 +151,12 @@ export default function combineReducers(reducers) {
}
if (process.env.NODE_ENV !== 'production') {
const warningMessage = getUnexpectedStateShapeWarningMessage(state, finalReducers, action, unexpectedKeyCache)
const warningMessage = getUnexpectedStateShapeWarningMessage(
state,
finalReducers,
action,
unexpectedKeyCache
)
if (warningMessage) {
warning(warningMessage)
}
View
@@ -67,8 +67,8 @@ export default function createStore(reducer, preloadedState, enhancer) {
if (isDispatching) {
throw new Error(
'You may not call store.getState() while the reducer is executing. ' +
'The reducer has already received the state as an argument. ' +
'Pass it down from the top reducer instead of reading it from the store.'
'The reducer has already received the state as an argument. ' +
'Pass it down from the top reducer instead of reading it from the store.'
)
}
@@ -106,9 +106,9 @@ export default function createStore(reducer, preloadedState, enhancer) {
if (isDispatching) {
throw new Error(
'You may not call store.subscribe() while the reducer is executing. ' +
'If you would like to be notified after the store has been updated, subscribe from a ' +
'component and invoke store.getState() in the callback to access the latest state. ' +
'See http://redux.js.org/docs/api/Store.html#subscribe for more details.'
'If you would like to be notified after the store has been updated, subscribe from a ' +
'component and invoke store.getState() in the callback to access the latest state. ' +
'See http://redux.js.org/docs/api/Store.html#subscribe for more details.'
)
}
@@ -125,7 +125,7 @@ export default function createStore(reducer, preloadedState, enhancer) {
if (isDispatching) {
throw new Error(
'You may not unsubscribe from a store listener while the reducer is executing. ' +
'See http://redux.js.org/docs/api/Store.html#subscribe for more details.'
'See http://redux.js.org/docs/api/Store.html#subscribe for more details.'
)
}
@@ -166,14 +166,14 @@ export default function createStore(reducer, preloadedState, enhancer) {
if (!isPlainObject(action)) {
throw new Error(
'Actions must be plain objects. ' +
'Use custom middleware for async actions.'
'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?'
'Have you misspelled a constant?'
)
}
@@ -188,7 +188,7 @@ export default function createStore(reducer, preloadedState, enhancer) {
isDispatching = false
}
const listeners = currentListeners = nextListeners
const listeners = (currentListeners = nextListeners)
for (let i = 0; i < listeners.length; i++) {
const listener = listeners[i]
listener()
View
@@ -18,11 +18,11 @@ if (
isCrushed.name !== 'isCrushed'
) {
warning(
'You are currently using minified code outside of NODE_ENV === \'production\'. ' +
'This means that you are running a slower development build of Redux. ' +
'You can use loose-envify (https://github.com/zertosh/loose-envify) for browserify ' +
'or DefinePlugin for webpack (http://stackoverflow.com/questions/30030031) ' +
'to ensure you have the correct code for your production build.'
"You are currently using minified code outside of NODE_ENV === 'production'. " +
'This means that you are running a slower development build of Redux. ' +
'You can use loose-envify (https://github.com/zertosh/loose-envify) for browserify ' +
'or DefinePlugin for webpack (http://stackoverflow.com/questions/30030031) ' +
'to ensure you have the correct code for your production build.'
)
}
View
@@ -5,8 +5,20 @@
* Do not reference these action types directly in your code.
*/
const ActionTypes = {
INIT: '@@redux/INIT' + Math.random().toString(36).substring(7).split('').join('.'),
REPLACE: '@@redux/REPLACE' + Math.random().toString(36).substring(7).split('').join('.')
INIT:
'@@redux/INIT' +
Math.random()
.toString(36)
.substring(7)
.split('')
.join('.'),
REPLACE:
'@@redux/REPLACE' +
Math.random()
.toString(36)
.substring(7)
.split('')
.join('.')
}
export default ActionTypes
View
@@ -15,7 +15,5 @@ export default function warning(message) {
// "break on all exceptions" in your console,
// it would pause the execution at this line.
throw new Error(message)
/* eslint-disable no-empty */
} catch (e) { }
/* eslint-enable no-empty */
} catch (e) {} // eslint-disable-line no-empty
}
@@ -34,7 +34,10 @@ describe('applyMiddleware', () => {
expect(spy.mock.calls[0][0]).toHaveProperty('getState')
expect(spy.mock.calls[0][0]).toHaveProperty('dispatch')
expect(store.getState()).toEqual([ { id: 1, text: 'Use Redux' }, { id: 2, text: 'Flux FTW!' } ])
expect(store.getState()).toEqual([
{ id: 1, text: 'Use Redux' },
{ id: 2, text: 'Flux FTW!' }
])
})
it('passes recursive dispatches through the middleware chain', () => {
@@ -120,7 +123,10 @@ describe('applyMiddleware', () => {
return next => action => dispatch(action, testCallArgs)
}
const store = createStore(reducers.todos, applyMiddleware(multiArgMiddleware, dummyMiddleware))
const store = createStore(
reducers.todos,
applyMiddleware(multiArgMiddleware, dummyMiddleware)
)
store.dispatch(spy)
expect(spy.mock.calls[0]).toEqual(testCallArgs)
Oops, something went wrong.

0 comments on commit 87071fd

Please sign in to comment.