This repository has been archived by the owner on Jun 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
111 additions
and
63 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
declare type RouterTo = string | LocationShape | URL; | ||
|
||
declare type Match = { | ||
params: Params, | ||
isExact: boolean, | ||
path: string, | ||
url: string, | ||
}; | ||
|
||
declare type MatchedRoute = { route: PlatformRoute, match: Match }; | ||
declare type MatchPathOptions = { | ||
path: string, | ||
exact?: boolean, | ||
strict?: boolean, | ||
}; | ||
|
||
declare module 'react-router-dom/matchPath' { | ||
declare function matchPath( | ||
pathname: string, | ||
options: MatchPathOptions | ||
): null | Match; | ||
declare module.exports: typeof matchPath; | ||
} | ||
|
||
declare type LocationShape = { | ||
pathname?: string, | ||
search?: string, | ||
hash?: string, | ||
state?: any, | ||
}; | ||
|
||
declare class RouterRedirect extends React$Component { | ||
props: { | ||
to: string | LocationShape, | ||
push?: boolean, | ||
}, | ||
} | ||
declare module 'react-router-dom/Redirect' { | ||
declare export default typeof RouterRedirect | ||
} | ||
|
||
declare type LocationAction = { type: string, payload: LocationShape }; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// @flow | ||
import { LOCATION_CHANGE, SERVER_RENDER } from './routeActionCreators'; | ||
/* | ||
* Store routing state to allow middleware to record more accurate | ||
* tracking info | ||
*/ | ||
export default function routing( | ||
state: { location?: LocationShape, referrer?: LocationShape | {} } = {}, | ||
action: LocationAction | ||
) { | ||
if (action.type === LOCATION_CHANGE || action.type === SERVER_RENDER) { | ||
return { | ||
referrer: state.location || {}, | ||
location: action.payload, | ||
}; | ||
} | ||
return state; | ||
} |
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import * as redux from 'redux'; | ||
import makeRootReducer, { platformReducers } from './reducer'; | ||
/** | ||
* A function that builds a reducer combining platform-standard reducers and | ||
* app-specific reducers | ||
export default function makeRootReducer(appReducers = {}) { | ||
Object.keys(appReducers).forEach(reducer => { | ||
if (reducer in platformReducers) { | ||
throw new Error(`'${reducer}' is a reserved platform reducer name`); | ||
} | ||
}); | ||
return combineReducers({ | ||
...platformReducers, | ||
...appReducers, | ||
}); | ||
} | ||
*/ | ||
redux.combineReducers = jest.fn(); | ||
|
||
describe('makeRootReducer', () => { | ||
it('calls combineReducers with platform reducers + supplied reducers', () => { | ||
redux.combineReducers.mockClear(); | ||
const foo = () => {}; | ||
const appReducers = { foo }; | ||
makeRootReducer(appReducers); | ||
expect(redux.combineReducers).toHaveBeenCalled(); | ||
const calledWith = redux.combineReducers.mock.calls[0][0]; | ||
expect(calledWith).toMatchObject(platformReducers); // all platform reducers | ||
expect(calledWith).toMatchObject(appReducers); // additional app reducer | ||
}); | ||
|
||
it('throws error when attempting to overwrite a platform reducer', () => { | ||
const invalidReducerKey = Object.keys(platformReducers)[0]; | ||
expect(() => | ||
makeRootReducer({ | ||
[invalidReducerKey]: platformReducers[invalidReducerKey], | ||
}) | ||
).toThrow(); | ||
}); | ||
}); |
This file contains 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