Skip to content
This repository has been archived by the owner on May 23, 2018. It is now read-only.

Commit

Permalink
feat: add first draft of a Link and RouteNodeMixin factories
Browse files Browse the repository at this point in the history
  • Loading branch information
troch committed Jul 2, 2015
1 parent 3f2ef7c commit 5799da7
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
7 changes: 7 additions & 0 deletions modules/index.js
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
}
30 changes: 30 additions & 0 deletions modules/link-factory.js
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>
}
})
}
15 changes: 15 additions & 0 deletions modules/segment-mixin-factory.js
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)
}
})
})
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
},
"homepage": "http://router5.github.com/router5/router5-react",
"devDependencies": {
"router5": "0.0.1-alpha.3"
"router5": "0.0.1-alpha.4"
},
"peerDependencies": {
"router5": "0.0.1-alpha.3"
"router5": "0.0.1-alpha.4"
}
}

0 comments on commit 5799da7

Please sign in to comment.