Skip to content
This repository was archived by the owner on Oct 26, 2018. It is now read-only.

Commit d01455f

Browse files
committed
Merge pull request #91 from kjbekkelund/rackt-eslint
Add rackt eslint config
2 parents 011a16d + 109d1ed commit d01455f

File tree

6 files changed

+221
-212
lines changed

6 files changed

+221
-212
lines changed

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "rackt"
3+
}

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"license": "MIT",
1414
"scripts": {
1515
"build": "mkdir -p lib && babel ./src/index.js --out-file ./lib/index.js",
16+
"lint": "eslint src test",
1617
"test": "npm run test:node && npm run test:browser",
1718
"test:node": "mocha --compilers js:babel-core/register --recursive ./test/node",
1819
"test:browser": "karma start",
@@ -34,9 +35,12 @@
3435
"devDependencies": {
3536
"babel-cli": "^6.1.2",
3637
"babel-core": "^6.2.1",
38+
"babel-eslint": "^4.1.6",
3739
"babel-loader": "^6.2.0",
3840
"babel-plugin-transform-object-assign": "^6.0.14",
3941
"babel-preset-es2015": "^6.1.2",
42+
"eslint": "^1.10.3",
43+
"eslint-config-rackt": "^1.1.1",
4044
"expect": "^1.13.0",
4145
"history": "^1.13.1",
4246
"isparta": "^4.0.0",

src/index.js

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const deepEqual = require('deep-equal');
1+
const deepEqual = require('deep-equal')
22

33
// Constants
44

5-
const INIT_PATH = "@@router/INIT_PATH";
6-
const UPDATE_PATH = "@@router/UPDATE_PATH";
7-
const SELECT_STATE = state => state.routing;
5+
const INIT_PATH = '@@router/INIT_PATH'
6+
const UPDATE_PATH = '@@router/UPDATE_PATH'
7+
const SELECT_STATE = state => state.routing
88

99
// Action creators
1010

@@ -17,7 +17,7 @@ function initPath(path, state) {
1717
replace: false,
1818
avoidRouterUpdate: true
1919
}
20-
};
20+
}
2121
}
2222

2323
function pushPath(path, state, { avoidRouterUpdate = false } = {}) {
@@ -29,7 +29,7 @@ function pushPath(path, state, { avoidRouterUpdate = false } = {}) {
2929
replace: false,
3030
avoidRouterUpdate: !!avoidRouterUpdate
3131
}
32-
};
32+
}
3333
}
3434

3535
function replacePath(path, state, { avoidRouterUpdate = false } = {}) {
@@ -51,7 +51,7 @@ let initialState = {
5151
path: undefined,
5252
state: undefined,
5353
replace: false
54-
};
54+
}
5555

5656
function update(state=initialState, { type, payload }) {
5757
if(type === INIT_PATH || type === UPDATE_PATH) {
@@ -60,19 +60,19 @@ function update(state=initialState, { type, payload }) {
6060
changeId: state.changeId + (payload.avoidRouterUpdate ? 0 : 1),
6161
state: payload.state,
6262
replace: payload.replace
63-
});
63+
})
6464
}
65-
return state;
65+
return state
6666
}
6767

6868
// Syncing
6969

7070
function locationsAreEqual(a, b) {
71-
return a != null && b != null && a.path === b.path && deepEqual(a.state, b.state);
71+
return a != null && b != null && a.path === b.path && deepEqual(a.state, b.state)
7272
}
7373

7474
function syncReduxAndRouter(history, store, selectRouterState = SELECT_STATE) {
75-
const getRouterState = () => selectRouterState(store.getState());
75+
const getRouterState = () => selectRouterState(store.getState())
7676

7777
// To properly handle store updates we need to track the last route.
7878
// This route contains a `changeId` which is updated on every
@@ -81,20 +81,20 @@ function syncReduxAndRouter(history, store, selectRouterState = SELECT_STATE) {
8181
// check if the location has changed, and if it is we trigger a
8282
// history update. It's possible for this to happen when something
8383
// reloads the entire app state such as redux devtools.
84-
let lastRoute = undefined;
84+
let lastRoute = undefined
8585

8686
if(!getRouterState()) {
8787
throw new Error(
88-
"Cannot sync router: route state does not exist. Did you " +
89-
"install the routing reducer?"
90-
);
88+
'Cannot sync router: route state does not exist. Did you ' +
89+
'install the routing reducer?'
90+
)
9191
}
9292

9393
const unsubscribeHistory = history.listen(location => {
9494
const route = {
9595
path: history.createPath(location),
9696
state: location.state
97-
};
97+
}
9898

9999
if (!lastRoute) {
100100
// `initialState` *should* represent the current location when
@@ -112,40 +112,40 @@ function syncReduxAndRouter(history, store, selectRouterState = SELECT_STATE) {
112112
path: route.path,
113113
state: route.state,
114114
replace: false
115-
};
115+
}
116116

117117
// Also set `lastRoute` so that the store subscriber doesn't
118118
// trigger an unnecessary `pushState` on load
119-
lastRoute = initialState;
119+
lastRoute = initialState
120120

121-
store.dispatch(initPath(route.path, route.state));
121+
store.dispatch(initPath(route.path, route.state))
122122
} else if(!locationsAreEqual(getRouterState(), route)) {
123123
// The above check avoids dispatching an action if the store is
124124
// already up-to-date
125-
const method = location.action === 'REPLACE' ? replacePath : pushPath;
126-
store.dispatch(method(route.path, route.state, { avoidRouterUpdate: true }));
125+
const method = location.action === 'REPLACE' ? replacePath : pushPath
126+
store.dispatch(method(route.path, route.state, { avoidRouterUpdate: true }))
127127
}
128-
});
128+
})
129129

130130
const unsubscribeStore = store.subscribe(() => {
131-
let routing = getRouterState();
131+
let routing = getRouterState()
132132

133133
// Only trigger history update if this is a new change or the
134134
// location has changed.
135135
if(lastRoute.changeId !== routing.changeId ||
136136
!locationsAreEqual(lastRoute, routing)) {
137137

138-
lastRoute = routing;
139-
const method = routing.replace ? 'replaceState' : 'pushState';
140-
history[method](routing.state, routing.path);
138+
lastRoute = routing
139+
const method = routing.replace ? 'replaceState' : 'pushState'
140+
history[method](routing.state, routing.path)
141141
}
142142

143-
});
143+
})
144144

145145
return function unsubscribe() {
146-
unsubscribeHistory();
147-
unsubscribeStore();
148-
};
146+
unsubscribeHistory()
147+
unsubscribeStore()
148+
}
149149
}
150150

151151
module.exports = {
@@ -154,4 +154,4 @@ module.exports = {
154154
replacePath,
155155
syncReduxAndRouter,
156156
routeReducer: update
157-
};
157+
}

test/browser/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const { createHashHistory, createHistory } = require('history');
2-
const createTests = require('../createTests.js');
1+
const { createHashHistory, createHistory } = require('history')
2+
const createTests = require('../createTests.js')
33

4-
createTests(createHashHistory, 'Hash History', () => window.location = '#/');
5-
createTests(createHistory, 'Browser History', () => window.history.replaceState(null, null, '/'));
4+
createTests(createHashHistory, 'Hash History', () => window.location = '#/')
5+
createTests(createHistory, 'Browser History', () => window.history.replaceState(null, null, '/'))

0 commit comments

Comments
 (0)