Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update variables to ES6 #2169

Merged
merged 4 commits into from
Dec 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"extends": "rackt",
"rules": {
"valid-jsdoc": 2,
// Disable until Flow supports let and const
"no-var": 0,
"no-var": 2,
"prefer-const": 2,
"react/jsx-uses-react": 1,
"react/jsx-no-undef": 2,
"react/wrap-multilines": 2
Expand Down
2 changes: 1 addition & 1 deletion build/use-lodash-es.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = function () {
return {
visitor: {
ImportDeclaration(path) {
var source = path.node.source
const source = path.node.source
source.value = source.value.replace(/^lodash($|\/)/, 'lodash-es$1')
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/applyMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import compose from './compose'
*/
export default function applyMiddleware(...middlewares) {
return (createStore) => (reducer, preloadedState, enhancer) => {
var store = createStore(reducer, preloadedState, enhancer)
var dispatch = store.dispatch
var chain = []
const store = createStore(reducer, preloadedState, enhancer)
let dispatch = store.dispatch
let chain = []

var middlewareAPI = {
const middlewareAPI = {
getState: store.getState,
dispatch: (action) => dispatch(action)
}
Expand Down
10 changes: 5 additions & 5 deletions src/bindActionCreators.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ export default function bindActionCreators(actionCreators, dispatch) {
)
}

var keys = Object.keys(actionCreators)
var boundActionCreators = {}
for (var i = 0; i < keys.length; i++) {
var key = keys[i]
var actionCreator = actionCreators[key]
const keys = Object.keys(actionCreators)
const boundActionCreators = {}
for (let i = 0; i < keys.length; i++) {
const key = keys[i]
const actionCreator = actionCreators[key]
if (typeof actionCreator === 'function') {
boundActionCreators[key] = bindActionCreator(actionCreator, dispatch)
}
Expand Down
51 changes: 26 additions & 25 deletions src/combineReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { ActionTypes } from './createStore'
import isPlainObject from 'lodash/isPlainObject'
import warning from './utils/warning'

var NODE_ENV = typeof process !== 'undefined' ? process.env.NODE_ENV : 'development'
const NODE_ENV = typeof process !== 'undefined' ? process.env.NODE_ENV : 'development'

function getUndefinedStateErrorMessage(key, action) {
var actionType = action && action.type
var actionName = actionType && `"${actionType.toString()}"` || 'an action'
const actionType = action && action.type
const actionName = actionType && `"${actionType.toString()}"` || 'an action'

return (
`Given action ${actionName}, reducer "${key}" returned undefined. ` +
Expand All @@ -15,8 +15,8 @@ function getUndefinedStateErrorMessage(key, action) {
}

function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, unexpectedKeyCache) {
var reducerKeys = Object.keys(reducers)
var argumentName = action && action.type === ActionTypes.INIT ?
const reducerKeys = Object.keys(reducers)
const argumentName = action && action.type === ActionTypes.INIT ?
'preloadedState argument passed to createStore' :
'previous state received by the reducer'

Expand All @@ -36,7 +36,7 @@ function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, une
)
}

var unexpectedKeys = Object.keys(inputState).filter(key =>
const unexpectedKeys = Object.keys(inputState).filter(key =>
!reducers.hasOwnProperty(key) &&
!unexpectedKeyCache[key]
)
Expand All @@ -57,8 +57,8 @@ function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, une

function assertReducerSanity(reducers) {
Object.keys(reducers).forEach(key => {
var reducer = reducers[key]
var initialState = reducer(undefined, { type: ActionTypes.INIT })
const reducer = reducers[key]
const initialState = reducer(undefined, { type: ActionTypes.INIT })

if (typeof initialState === 'undefined') {
throw new Error(
Expand All @@ -69,7 +69,7 @@ function assertReducerSanity(reducers) {
)
}

var 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. ` +
Expand Down Expand Up @@ -100,10 +100,10 @@ function assertReducerSanity(reducers) {
* passed object, and builds a state object with the same shape.
*/
export default function combineReducers(reducers) {
var reducerKeys = Object.keys(reducers)
var finalReducers = {}
for (var i = 0; i < reducerKeys.length; i++) {
var key = reducerKeys[i]
const reducerKeys = Object.keys(reducers)
const finalReducers = {}
for (let i = 0; i < reducerKeys.length; i++) {
const key = reducerKeys[i]

if (NODE_ENV !== 'production') {
if (typeof reducers[key] === 'undefined') {
Expand All @@ -115,13 +115,14 @@ export default function combineReducers(reducers) {
finalReducers[key] = reducers[key]
}
}
var finalReducerKeys = Object.keys(finalReducers)
const finalReducerKeys = Object.keys(finalReducers)

let unexpectedKeyCache
if (NODE_ENV !== 'production') {
var unexpectedKeyCache = {}
unexpectedKeyCache = {}
}

var sanityError
let sanityError
try {
assertReducerSanity(finalReducers)
} catch (e) {
Expand All @@ -134,21 +135,21 @@ export default function combineReducers(reducers) {
}

if (NODE_ENV !== 'production') {
var warningMessage = getUnexpectedStateShapeWarningMessage(state, finalReducers, action, unexpectedKeyCache)
const warningMessage = getUnexpectedStateShapeWarningMessage(state, finalReducers, action, unexpectedKeyCache)
if (warningMessage) {
warning(warningMessage)
}
}

var hasChanged = false
var nextState = {}
for (var i = 0; i < finalReducerKeys.length; i++) {
var key = finalReducerKeys[i]
var reducer = finalReducers[key]
var previousStateForKey = state[key]
var nextStateForKey = reducer(previousStateForKey, action)
let hasChanged = false
const nextState = {}
for (let i = 0; i < finalReducerKeys.length; i++) {
const key = finalReducerKeys[i]
const reducer = finalReducers[key]
const previousStateForKey = state[key]
const nextStateForKey = reducer(previousStateForKey, action)
if (typeof nextStateForKey === 'undefined') {
var errorMessage = getUndefinedStateErrorMessage(key, action)
const errorMessage = getUndefinedStateErrorMessage(key, action)
throw new Error(errorMessage)
}
nextState[key] = nextStateForKey
Expand Down
26 changes: 13 additions & 13 deletions src/createStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import $$observable from 'symbol-observable'
* If the current state is undefined, you must return the initial state.
* Do not reference these action types directly in your code.
*/
export var ActionTypes = {
export const ActionTypes = {
INIT: '@@redux/INIT'
}

Expand Down Expand Up @@ -54,11 +54,11 @@ export default function createStore(reducer, preloadedState, enhancer) {
throw new Error('Expected the reducer to be a function.')
}

var currentReducer = reducer
var currentState = preloadedState
var currentListeners = []
var nextListeners = currentListeners
var isDispatching = false
let currentReducer = reducer
let currentState = preloadedState
let currentListeners = []
let nextListeners = currentListeners
let isDispatching = false

function ensureCanMutateNextListeners() {
if (nextListeners === currentListeners) {
Expand Down Expand Up @@ -103,7 +103,7 @@ export default function createStore(reducer, preloadedState, enhancer) {
throw new Error('Expected listener to be a function.')
}

var isSubscribed = true
let isSubscribed = true

ensureCanMutateNextListeners()
nextListeners.push(listener)
Expand All @@ -116,7 +116,7 @@ export default function createStore(reducer, preloadedState, enhancer) {
isSubscribed = false

ensureCanMutateNextListeners()
var index = nextListeners.indexOf(listener)
const index = nextListeners.indexOf(listener)
nextListeners.splice(index, 1)
}
}
Expand Down Expand Up @@ -172,9 +172,9 @@ export default function createStore(reducer, preloadedState, enhancer) {
isDispatching = false
}

var listeners = currentListeners = nextListeners
for (var i = 0; i < listeners.length; i++) {
var listener = listeners[i]
const listeners = currentListeners = nextListeners
for (let i = 0; i < listeners.length; i++) {
const listener = listeners[i]
listener()
}

Expand Down Expand Up @@ -207,7 +207,7 @@ export default function createStore(reducer, preloadedState, enhancer) {
* https://github.com/zenparsing/es-observable
*/
function observable() {
var outerSubscribe = subscribe
const outerSubscribe = subscribe
return {
/**
* The minimal observable subscription method.
Expand All @@ -229,7 +229,7 @@ export default function createStore(reducer, preloadedState, enhancer) {
}

observeState()
var unsubscribe = outerSubscribe(observeState)
const unsubscribe = outerSubscribe(observeState)
return { unsubscribe }
},

Expand Down