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

Commit

Permalink
feat: register listener in mixin only if existing
Browse files Browse the repository at this point in the history
  • Loading branch information
troch committed Jul 8, 2015
1 parent 618157b commit 8a388fa
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 22 deletions.
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,26 @@ and mixins as functional as possible.
This makes the use of Router5 with React very flexible, and you can choose how to organise your
code. Below is one example of how you can use those helpers:


```javascript
import React from 'react'
import {Router5} from 'router5'
import {linkFactory, segmentMixinFactory} from 'router5-react'
import Router5 from 'router5'

let router = Router5()
.addNode('users', '/users')
.addNode('users.view', '/view/:id')
.addNode('users.list', '/list')
var router = new Router5()
.setOption('useHash', true)
.setOption('defaultRoute', 'inbox')
// Routes
.addNode('inbox', '/inbox')
.addNode('inbox.message', '/message/:id')
.addNode('compose', '/compose')
.addNode('contacts', '/contacts')
.start()

export {
Link: linkFactory(router)
SegmentMixin: segmentMixinFactory(router)
router
}
var Link = linkFactory(router)
var SegmentMixin = segmentMixinFactory(router)

export {router, Link, SegmentMixin}
```

### Link component
Expand All @@ -45,7 +50,7 @@ let Menu = React.createClass({
render() {
let params = {id: 1}
return (<nav>
<Link routeName="users.view" routeParams={params}>View user 1</Link>
<Link routeName="users.view" routeParams={params} routeOptions={reload: true}>View user 1</Link>

<Link routeName="users.list">List users</Link>
</nav>)
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "router5-react",
"version": "0.1.0-alpha.6",
"version": "0.1.0-alpha.7",
"homepage": "http://router5.github.io",
"authors": [
"Thomas Roch <thomas.c.roch@gmail.com>"
Expand Down
4 changes: 2 additions & 2 deletions dist/amd/segment-mixin-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ define(["exports", "module"], function (exports, module) {
},

componentDidMount: function componentDidMount() {
router.addNodeListener(routeName, this.nodeListener);
if (listener) router.addNodeListener(routeName, this.nodeListener);
router.registerComponent(routeName, this);
},

componentWillUnmount: function componentWillUnmount() {
router.removeNodeListener(routeName, this.nodeListener);
if (listener) router.removeNodeListener(routeName, this.nodeListener);
router.deregisterComponent(routeName, this);
}
};
Expand Down
4 changes: 2 additions & 2 deletions dist/browser/router5-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ function segmentMixinFactory(router) {
},

componentDidMount: function componentDidMount() {
router.addNodeListener(routeName, this.nodeListener);
if (listener) router.addNodeListener(routeName, this.nodeListener);
router.registerComponent(routeName, this);
},

componentWillUnmount: function componentWillUnmount() {
router.removeNodeListener(routeName, this.nodeListener);
if (listener) router.removeNodeListener(routeName, this.nodeListener);
router.deregisterComponent(routeName, this);
}
};
Expand Down
2 changes: 1 addition & 1 deletion dist/browser/router5-react.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/commonjs/segment-mixin-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ function segmentMixinFactory(router) {
},

componentDidMount: function componentDidMount() {
router.addNodeListener(routeName, this.nodeListener);
if (listener) router.addNodeListener(routeName, this.nodeListener);
router.registerComponent(routeName, this);
},

componentWillUnmount: function componentWillUnmount() {
router.removeNodeListener(routeName, this.nodeListener);
if (listener) router.removeNodeListener(routeName, this.nodeListener);
router.deregisterComponent(routeName, this);
}
};
Expand Down
4 changes: 2 additions & 2 deletions modules/segment-mixin-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ function segmentMixinFactory(router) {
},

componentDidMount() {
router.addNodeListener(routeName, this.nodeListener)
if (listener) router.addNodeListener(routeName, this.nodeListener)
router.registerComponent(routeName, this)
},

componentWillUnmount() {
router.removeNodeListener(routeName, this.nodeListener)
if (listener) router.removeNodeListener(routeName, this.nodeListener)
router.deregisterComponent(routeName, this)
}
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "router5-react",
"version": "0.1.0-alpha.6",
"version": "0.1.0-alpha.7",
"description": "router5 helpers for React",
"main": "dist/commonjs/index.js",
"scripts": {
Expand Down

0 comments on commit 8a388fa

Please sign in to comment.