Browse code
Reformat and add semicolons
Ed Langley authored on 17/06/2017 00:50:19
Showing 6 changed files
Showing 6 changed files
- package.json
- src/action-router.js
- src/change-url-event.js
- src/change-url-event.test.js
- src/fragment.js
- src/fragment.test.js
... | ... |
@@ -1,58 +1,58 @@ |
1 | 1 |
{ |
2 |
- "name": "routedux", |
|
3 |
- "contributors": [ |
|
4 |
- { |
|
5 |
- "name": "Maximilian Summe", |
|
6 |
- "email": "msumme@gmail.com" |
|
7 |
- }, |
|
8 |
- { |
|
9 |
- "name": "Edward Langley", |
|
10 |
- "email": "el-os@elangley.org" |
|
11 |
- } |
|
12 |
- ], |
|
13 |
- "main": "dist/index.js", |
|
14 |
- "version": "0.1.5", |
|
15 |
- "license": "MIT", |
|
16 |
- "dependencies": { |
|
17 |
- "ramda": "^0.24.1", |
|
18 |
- "redux": "^3.6.0" |
|
19 |
- }, |
|
20 |
- "devDependencies": { |
|
21 |
- "babel-cli": "^6.24.1", |
|
22 |
- "babel-preset-flow": "^6.23.0", |
|
23 |
- "babel-preset-stage-3": "^6.24.1", |
|
24 |
- "enzyme": "^2.8.2", |
|
25 |
- "enzyme-to-json": "^1.5.1", |
|
26 |
- "flow": "^0.2.3", |
|
27 |
- "flow-bin": "^0.48.0", |
|
28 |
- "flow-typed": "^2.1.2", |
|
29 |
- "react": "^15.6.0", |
|
30 |
- "react-dom": "^15.6.0", |
|
31 |
- "react-scripts": "1.0.7", |
|
32 |
- "react-test-renderer": "^15.5.4" |
|
33 |
- }, |
|
34 |
- "scripts": { |
|
35 |
- "start": "react-scripts start", |
|
36 |
- "build": "babel src -d dist", |
|
37 |
- "test": "react-scripts test --env=jsdom", |
|
38 |
- "eject": "react-scripts eject", |
|
39 |
- "flow": "flow" |
|
2 |
+ "name": "routedux", |
|
3 |
+ "contributors": [ |
|
4 |
+ { |
|
5 |
+ "name": "Maximilian Summe", |
|
6 |
+ "email": "msumme@gmail.com" |
|
40 | 7 |
}, |
41 |
- "npmFileMap": [ |
|
42 |
- { |
|
43 |
- "basePath": "/dist/", |
|
44 |
- "files": [ |
|
45 |
- "*.js" |
|
46 |
- ] |
|
47 |
- } |
|
8 |
+ { |
|
9 |
+ "name": "Edward Langley", |
|
10 |
+ "email": "el-os@elangley.org" |
|
11 |
+ } |
|
12 |
+ ], |
|
13 |
+ "main": "dist/index.js", |
|
14 |
+ "version": "0.1.5", |
|
15 |
+ "license": "MIT", |
|
16 |
+ "dependencies": { |
|
17 |
+ "ramda": "^0.24.1", |
|
18 |
+ "redux": "^3.6.0" |
|
19 |
+ }, |
|
20 |
+ "devDependencies": { |
|
21 |
+ "babel-cli": "^6.24.1", |
|
22 |
+ "babel-preset-flow": "^6.23.0", |
|
23 |
+ "babel-preset-stage-3": "^6.24.1", |
|
24 |
+ "enzyme": "^2.8.2", |
|
25 |
+ "enzyme-to-json": "^1.5.1", |
|
26 |
+ "flow": "^0.2.3", |
|
27 |
+ "flow-bin": "^0.48.0", |
|
28 |
+ "flow-typed": "^2.1.2", |
|
29 |
+ "react": "^15.6.0", |
|
30 |
+ "react-dom": "^15.6.0", |
|
31 |
+ "react-scripts": "1.0.7", |
|
32 |
+ "react-test-renderer": "^15.5.4" |
|
33 |
+ }, |
|
34 |
+ "scripts": { |
|
35 |
+ "start": "react-scripts start", |
|
36 |
+ "build": "babel src -d dist", |
|
37 |
+ "test": "react-scripts test --env=jsdom", |
|
38 |
+ "eject": "react-scripts eject", |
|
39 |
+ "flow": "flow" |
|
40 |
+ }, |
|
41 |
+ "npmFileMap": [ |
|
42 |
+ { |
|
43 |
+ "basePath": "/dist/", |
|
44 |
+ "files": [ |
|
45 |
+ "*.js" |
|
46 |
+ ] |
|
47 |
+ } |
|
48 |
+ ], |
|
49 |
+ "babel": { |
|
50 |
+ "plugins": [ |
|
51 |
+ "transform-react-jsx" |
|
48 | 52 |
], |
49 |
- "babel": { |
|
50 |
- "plugins": [ |
|
51 |
- "transform-react-jsx" |
|
52 |
- ], |
|
53 |
- "presets": [ |
|
54 |
- "env", |
|
53 |
+ "presets": [ |
|
54 |
+ "env", |
|
55 | 55 |
"stage-3" |
56 |
- ] |
|
57 |
- } |
|
56 |
+ ] |
|
57 |
+ } |
|
58 | 58 |
} |
... | ... |
@@ -12,7 +12,7 @@ function mostSpecificRouteMatch(match1, match2) { |
12 | 12 |
|
13 | 13 |
const paramLength1 = match1.routeParams.length; |
14 | 14 |
const paramLength2 = match2.routeParams.length; |
15 |
- let findWildcard = R.compose(R.findIndex.bind(R, isWildcard), pathSplit) |
|
15 |
+ let findWildcard = R.compose(R.findIndex.bind(R, isWildcard), pathSplit); |
|
16 | 16 |
|
17 | 17 |
let result = (paramLength1 > paramLength2) ? match2 : match1; |
18 | 18 |
|
... | ... |
@@ -44,10 +44,10 @@ function matchRoute(loc, matchers) { |
44 | 44 |
|
45 | 45 |
if (matchedParams) { |
46 | 46 |
if (matcherType === 'exact') { |
47 |
- return buildMatch(matchedParams, route) |
|
48 |
- } else { |
|
49 |
- return mostSpecificRouteMatch(match, buildMatch(matchedParams, route)); |
|
50 |
- } |
|
47 |
+ return buildMatch(matchedParams, route); |
|
48 |
+ } else { |
|
49 |
+ return mostSpecificRouteMatch(match, buildMatch(matchedParams, route)); |
|
50 |
+ } |
|
51 | 51 |
} else { |
52 | 52 |
return match; |
53 | 53 |
} |
... | ... |
@@ -143,7 +143,7 @@ function makeRoute(path, action, extraParams) { |
143 | 143 |
const updateWildcard = (wildcards, match, input) => { |
144 | 144 |
const wildcardName = match.replace(':', ''); |
145 | 145 |
return Object.assign(wildcards, {[wildcardName]: input}); |
146 |
- } |
|
146 |
+ }; |
|
147 | 147 |
|
148 | 148 |
const routeMatcher = function (inputPath) { |
149 | 149 |
let result = null; |
... | ... |
@@ -166,14 +166,14 @@ function makeRoute(path, action, extraParams) { |
166 | 166 |
} |
167 | 167 |
|
168 | 168 |
if(match === input) { |
169 |
- return acc |
|
169 |
+ return acc; |
|
170 | 170 |
} else if (match[0] === ":") { |
171 | 171 |
return updateWildcard(acc, match, input); |
172 | 172 |
} else { |
173 | 173 |
return null; |
174 | 174 |
} |
175 | 175 |
}; |
176 |
- result = R.zip(normMatchPath, normInputPath).reduce(f, {}) |
|
176 |
+ result = R.zip(normMatchPath, normInputPath).reduce(f, {}); |
|
177 | 177 |
} |
178 | 178 |
|
179 | 179 |
return result; |
... | ... |
@@ -191,7 +191,7 @@ function makeRoute(path, action, extraParams) { |
191 | 191 |
routeParams, |
192 | 192 |
extraParams |
193 | 193 |
} |
194 |
- } |
|
194 |
+ }; |
|
195 | 195 |
} |
196 | 196 |
|
197 | 197 |
function getRouteByPath(pattern, matchers) { |
... | ... |
@@ -202,7 +202,7 @@ function normalizeWildcards(path) { |
202 | 202 |
let curIdx = 0; |
203 | 203 |
return path.map((el) => { |
204 | 204 |
if (isWildcard(el)) { |
205 |
- return `:wildcard${curIdx}` |
|
205 |
+ return `:wildcard${curIdx}`; |
|
206 | 206 |
} else { |
207 | 207 |
return el; |
208 | 208 |
} |
... | ... |
@@ -210,7 +210,7 @@ function normalizeWildcards(path) { |
210 | 210 |
} |
211 | 211 |
|
212 | 212 |
function routeAlreadyExists(compiledRouteMatchers, path) { |
213 |
- let result = compiledRouteMatchers.hasOwnProperty(path) |
|
213 |
+ let result = compiledRouteMatchers.hasOwnProperty(path); |
|
214 | 214 |
|
215 | 215 |
if (!result) { |
216 | 216 |
const normalizingSplit = R.compose(normalizeWildcards, pathSplit); |
... | ... |
@@ -219,7 +219,7 @@ function routeAlreadyExists(compiledRouteMatchers, path) { |
219 | 219 |
for (const otherPath of Object.keys(compiledRouteMatchers)) { |
220 | 220 |
const otherPathParts = normalizingSplit(otherPath); |
221 | 221 |
if (R.equals(pathParts, otherPathParts)) { |
222 |
- throw new Error(`invalid routing configuration — route ${path} overlaps with route ${otherPath}`) |
|
222 |
+ throw new Error(`invalid routing configuration — route ${path} overlaps with route ${otherPath}`); |
|
223 | 223 |
} |
224 | 224 |
} |
225 | 225 |
} |
... | ... |
@@ -252,8 +252,8 @@ function compileRoutes(routesConfig) { |
252 | 252 |
} |
253 | 253 |
return { |
254 | 254 |
compiledActionMatchers, // { ACTION: [Route] } |
255 |
- compiledRouteMatchers, // { PATH: Route } |
|
256 |
- } |
|
255 |
+ compiledRouteMatchers // { PATH: Route } |
|
256 |
+ }; |
|
257 | 257 |
} |
258 | 258 |
|
259 | 259 |
/////// |
... | ... |
@@ -270,7 +270,7 @@ function constructPath(match) { |
270 | 270 |
if (part[0] === ":") { |
271 | 271 |
const name = part.slice(1); |
272 | 272 |
const val = match.extractedParams.hasOwnProperty(name) |
273 |
- ? match.extractedParams[name] : match.extraParams[name]; |
|
273 |
+ ? match.extractedParams[name] : match.extraParams[name]; |
|
274 | 274 |
resultParts.push(val); |
275 | 275 |
} else { |
276 | 276 |
resultParts.push(part); |
... | ... |
@@ -294,7 +294,7 @@ function createActionDispatcher(routesConfig, window) { |
294 | 294 |
this.activateDispatcher(theStore); |
295 | 295 |
this.receiveLocation(window.location); |
296 | 296 |
return theStore; |
297 |
- } |
|
297 |
+ }; |
|
298 | 298 |
}, |
299 | 299 |
handleEvent(ev) { |
300 | 300 |
|
... | ... |
@@ -333,7 +333,7 @@ function createActionDispatcher(routesConfig, window) { |
333 | 333 |
function buildMiddleware(actionDispatcher) { |
334 | 334 |
return store => next => action => { |
335 | 335 |
if (actionDispatcher.handlesAction(action)) { |
336 |
- actionDispatcher.receiveAction(action, store); |
|
336 |
+ actionDispatcher.receiveAction(action, store); |
|
337 | 337 |
} |
338 | 338 |
return next(action); |
339 | 339 |
}; |
... | ... |
@@ -32,7 +32,7 @@ export default function addChangeUrlEvent(window) { |
32 | 32 |
} |
33 | 33 |
}; |
34 | 34 |
|
35 |
-// / make sure we fire urlchanged for these |
|
35 |
+ // / make sure we fire urlchanged for these |
|
36 | 36 |
wrapEvent(window, 'popstate', changeUrlEventCreator); |
37 | 37 |
wrapEvent(window, 'pushstate', changeUrlEventCreator); |
38 | 38 |
wrapEvent(window, 'replacestate', changeUrlEventCreator); |
... | ... |
@@ -76,7 +76,7 @@ it("given event handler should generate a urlchange event only when url changes" |
76 | 76 |
}); |
77 | 77 |
|
78 | 78 |
it("should only add url events 1x when addChangeUrlEvent is called on window more than 1x", () => { |
79 |
-// given |
|
79 |
+ // given |
|
80 | 80 |
const window = { |
81 | 81 |
location: { |
82 | 82 |
hash: '#hash', |
... | ... |
@@ -120,4 +120,4 @@ it("should only add url events 1x when addChangeUrlEvent is called on window mor |
120 | 120 |
expect(map[event].length).toEqual(1); |
121 | 121 |
} |
122 | 122 |
|
123 |
-}); |
|
124 | 123 |
\ No newline at end of file |
124 |
+}); |
... | ... |
@@ -1,13 +1,11 @@ |
1 |
- |
|
2 |
- |
|
3 | 1 |
export default function Fragment({state, filterOn, children}) { |
4 | 2 |
|
5 |
- let parts = filterOn.split('.'); |
|
6 |
- let cur = parts.reduce((cur, next) => cur ? cur[next] : cur, state); |
|
3 |
+ let parts = filterOn.split('.'); |
|
4 |
+ let cur = parts.reduce((cur, next) => cur ? cur[next] : cur, state); |
|
7 | 5 |
|
8 |
- if(cur) { |
|
9 |
- return children; |
|
10 |
- } else { |
|
11 |
- return null; |
|
12 |
- } |
|
13 |
-} |
|
14 | 6 |
\ No newline at end of file |
7 |
+ if(cur) { |
|
8 |
+ return children; |
|
9 |
+ } else { |
|
10 |
+ return null; |
|
11 |
+ } |
|
12 |
+} |
... | ... |
@@ -5,14 +5,15 @@ import {shallow} from 'enzyme'; |
5 | 5 |
|
6 | 6 |
|
7 | 7 |
it("should display when state is truthy", () => { |
8 |
- |
|
9 | 8 |
// given |
10 | 9 |
const state = {property : true}; |
11 | 10 |
// when |
12 | 11 |
|
13 |
- const wrapper = shallow(<Fragment state={state} filterOn="property"> |
|
12 |
+ const wrapper = shallow( |
|
13 |
+ <Fragment state={state} filterOn="property"> |
|
14 | 14 |
<div>Hello</div> |
15 |
- </Fragment>); |
|
15 |
+ </Fragment> |
|
16 |
+ ); |
|
16 | 17 |
|
17 | 18 |
// then |
18 | 19 |
expect(ezJson(wrapper)).toMatchSnapshot(); |
... | ... |
@@ -23,9 +24,11 @@ it("should not display when state is falsy", () => { |
23 | 24 |
const state = {property : undefined}; |
24 | 25 |
// when |
25 | 26 |
|
26 |
- const wrapper = shallow(<Fragment state={state} filterOn="property"> |
|
27 |
- <div>Hello</div> |
|
28 |
- </Fragment>); |
|
27 |
+ const wrapper = shallow( |
|
28 |
+ <Fragment state={state} filterOn="property"> |
|
29 |
+ <div>Hello</div> |
|
30 |
+ </Fragment> |
|
31 |
+ ); |
|
29 | 32 |
|
30 | 33 |
// then |
31 | 34 |
expect(ezJson(wrapper)).toEqual(null); |
... | ... |
@@ -36,9 +39,11 @@ it("should handle paths in the state tree", () => { |
36 | 39 |
const state = {property : {subproperty: true}}; |
37 | 40 |
// when |
38 | 41 |
|
39 |
- const wrapper = shallow(<Fragment state={state} filterOn="property.subproperty"> |
|
40 |
- <div>Hello</div> |
|
41 |
- </Fragment>); |
|
42 |
+ const wrapper = shallow( |
|
43 |
+ <Fragment state={state} filterOn="property.subproperty"> |
|
44 |
+ <div>Hello</div> |
|
45 |
+ </Fragment> |
|
46 |
+ ); |
|
42 | 47 |
|
43 | 48 |
// then |
44 | 49 |
expect(ezJson(wrapper)).toMatchSnapshot(); |
... | ... |
@@ -49,9 +54,11 @@ it("should handle arrays in the state tree", () => { |
49 | 54 |
const state = {property : [{bar: {}}]}; |
50 | 55 |
// when |
51 | 56 |
|
52 |
- const wrapper = shallow(<Fragment state={state} filterOn="property.0.bar"> |
|
53 |
- <div>Hello</div> |
|
54 |
- </Fragment>); |
|
57 |
+ const wrapper = shallow( |
|
58 |
+ <Fragment state={state} filterOn="property.0.bar"> |
|
59 |
+ <div>Hello</div> |
|
60 |
+ </Fragment> |
|
61 |
+ ); |
|
55 | 62 |
|
56 | 63 |
// then |
57 | 64 |
expect(ezJson(wrapper)).toMatchSnapshot(); |
... | ... |
@@ -61,9 +68,11 @@ it("should be falsy if missing state tree", () => { |
61 | 68 |
// given |
62 | 69 |
const state = {property : {subproperty: true}}; |
63 | 70 |
|
64 |
- const wrapper = shallow(<Fragment state={state} filterOn="property.missingproperty.something"> |
|
65 |
- <div>Hello</div> |
|
66 |
- </Fragment>); |
|
71 |
+ const wrapper = shallow( |
|
72 |
+ <Fragment state={state} filterOn="property.missingproperty.something"> |
|
73 |
+ <div>Hello</div> |
|
74 |
+ </Fragment> |
|
75 |
+ ); |
|
67 | 76 |
|
68 | 77 |
expect(ezJson(wrapper)).toEqual(null); |
69 | 78 |
|