-
Notifications
You must be signed in to change notification settings - Fork 10
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
15 changed files
with
494 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
{ | ||
"dist/curi-react-universal.es.js": { | ||
"bundled": 6794, | ||
"minified": 3460, | ||
"gzipped": 1205, | ||
"bundled": 8447, | ||
"minified": 4296, | ||
"gzipped": 1349, | ||
"treeshaked": { | ||
"rollup": { | ||
"code": 441, | ||
"code": 453, | ||
"import_statements": 21 | ||
}, | ||
"webpack": { | ||
"code": 1435 | ||
"code": 1449 | ||
} | ||
} | ||
}, | ||
"dist/curi-react-universal.js": { | ||
"bundled": 7093, | ||
"minified": 3704, | ||
"gzipped": 1292 | ||
"bundled": 8753, | ||
"minified": 4545, | ||
"gzipped": 1435 | ||
}, | ||
"dist/curi-react-universal.umd.js": { | ||
"bundled": 7632, | ||
"minified": 3460, | ||
"gzipped": 1250 | ||
"bundled": 9374, | ||
"minified": 4194, | ||
"gzipped": 1375 | ||
}, | ||
"dist/curi-react-universal.min.js": { | ||
"bundled": 7271, | ||
"minified": 3172, | ||
"gzipped": 1102 | ||
"bundled": 9013, | ||
"minified": 3906, | ||
"gzipped": 1226 | ||
} | ||
} |
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,41 @@ | ||
import React from "react"; | ||
|
||
import { Curious } from "./Context"; | ||
|
||
import { Navigation } from "@curi/router"; | ||
|
||
export interface FinishNavigationProps { | ||
children: any; | ||
} | ||
|
||
export interface BaseFinishNavigationProps extends FinishNavigationProps { | ||
navigation: Navigation; | ||
} | ||
|
||
class FinishNavigation extends React.Component<BaseFinishNavigationProps> { | ||
componentDidMount() { | ||
this.finish(); | ||
} | ||
|
||
componentDidUpdate() { | ||
this.finish(); | ||
} | ||
|
||
finish() { | ||
if (this.props.navigation.finish) { | ||
this.props.navigation.finish(); | ||
} | ||
} | ||
|
||
render() { | ||
return this.props.children; | ||
} | ||
} | ||
|
||
export default (props: FinishNavigationProps) => ( | ||
<Curious> | ||
{({ navigation }) => ( | ||
<FinishNavigation {...props} navigation={navigation} /> | ||
)} | ||
</Curious> | ||
); |
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,89 @@ | ||
import "jest"; | ||
import React from "react"; | ||
import ReactDOM from "react-dom"; | ||
import { curi, prepareRoutes } from "@curi/router"; | ||
import InMemory from "@hickory/in-memory"; | ||
|
||
// @ts-ignore (resolved by jest) | ||
import { curiProvider, FinishNavigation } from "@curi/react-universal"; | ||
|
||
describe("<FinishNavigation>", () => { | ||
let node; | ||
const routes = prepareRoutes([ | ||
{ name: "Home", path: "" }, | ||
{ name: "About", path: "about" } | ||
]); | ||
|
||
beforeEach(() => { | ||
node = document.createElement("div"); | ||
}); | ||
|
||
afterEach(() => { | ||
ReactDOM.unmountComponentAtNode(node); | ||
}); | ||
|
||
it('"finishes" navigation after mounting', () => { | ||
const history = InMemory(); | ||
const router = curi(history, routes, { suspend: true }); | ||
const Router = curiProvider(router); | ||
|
||
let navigations = []; | ||
// intercept and mock navigation.finish() | ||
router.observe( | ||
({ navigation }) => { | ||
navigation.finish = jest.fn(); | ||
navigations.push(navigation); | ||
} | ||
); | ||
|
||
ReactDOM.render( | ||
<Router> | ||
{({ navigation }) => { | ||
expect(navigation.finish.mock.calls.length).toBe(0); | ||
return ( | ||
<FinishNavigation> | ||
<div>Yo</div> | ||
</FinishNavigation> | ||
); | ||
}} | ||
</Router>, | ||
node, | ||
() => { | ||
expect(navigations[0].finish.mock.calls.length).toBe(1); | ||
} | ||
); | ||
}); | ||
|
||
it('"finishes" navigation after updating', () => { | ||
const history = InMemory(); | ||
const router = curi(history, routes, { suspend: true }); | ||
const Router = curiProvider(router); | ||
|
||
let navigations = []; | ||
// intercept and mock navigation.finish() | ||
router.observe( | ||
({ navigation }) => { | ||
navigation.finish = jest.fn(); | ||
navigations.push(navigation); | ||
} | ||
); | ||
|
||
ReactDOM.render( | ||
<Router> | ||
{({ navigation }) => { | ||
expect(navigation.finish.mock.calls.length).toBe(0); | ||
return ( | ||
<FinishNavigation> | ||
<div>Yo</div> | ||
</FinishNavigation> | ||
); | ||
}} | ||
</Router>, | ||
node | ||
); | ||
expect(navigations[0].finish.mock.calls.length).toBe(1); | ||
|
||
router.navigate({ name: "About" }); | ||
expect(navigations[1].finish.mock.calls.length).toBe(1); | ||
}); | ||
}); |
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,10 @@ | ||
/// <reference types="react" /> | ||
import { Navigation } from "@curi/router"; | ||
export interface FinishNavigationProps { | ||
children: any; | ||
} | ||
export interface BaseFinishNavigationProps extends FinishNavigationProps { | ||
navigation: Navigation; | ||
} | ||
declare const _default: (props: FinishNavigationProps) => JSX.Element; | ||
export default _default; |
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
Oops, something went wrong.