This repository has been archived by the owner on May 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add first draft of a Link and RouteNodeMixin factories
- Loading branch information
Showing
4 changed files
with
54 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import linkFactory from './link-factory' | ||
import segmentMixinFactory from './segment-mixin-factory' | ||
|
||
export default { | ||
linkFactory, | ||
segmentMixinFactory | ||
} |
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,30 @@ | ||
import React from 'react' | ||
|
||
export default router5LinkFactory | ||
|
||
let router5LinkFactory = (router) => { | ||
return React.createClass({ | ||
propTypes: { | ||
routeName: React.PropTypes.string.isRequired | ||
routeParams: React.PropTypes.object | ||
routeOptions: React.PropTypes.object | ||
}, | ||
|
||
shouldComponentUpdate(nextProps, nextState) { | ||
return !router.areStatesEqual( | ||
{name: nextProps.routeName, params: nextProps.routeParams}, | ||
{name: this.props.routeName, params: this.props.routeParams} | ||
) | ||
}, | ||
|
||
clickHandler(evt) { | ||
evt.preventDefault() | ||
router.navigate(this.props.routeName, this.props.routeParams, this.props.options) | ||
}, | ||
|
||
render() { | ||
let path = router.buildPath(this.props.routeName, this.props.routeParams) | ||
return <a href={path} onClick={clickHandler}></a> | ||
} | ||
}) | ||
} |
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,15 @@ | ||
export default segmentMixinFactory | ||
|
||
let segmentMixinFactory = (router) => { | ||
return (routeName, listener) => ({ | ||
componentDidMount() { | ||
router.addNodeListener(routeName, listener.bind(this)) | ||
router.registerComponent(routeName, this) | ||
}, | ||
|
||
componentWillUnmount() { | ||
router.addremoveNodeListener(routeName, listener.bind(this)) | ||
router.deregisterComponent(routeName, this) | ||
} | ||
}) | ||
}) |
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