This repository has been archived by the owner on Jun 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
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
5 changed files
with
159 additions
and
0 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,2 @@ | ||
node_modules/ | ||
npm-debug.log |
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,2 +1,4 @@ | ||
# router5-deku | ||
Helpers for using router5 with Deku | ||
|
||
See: [router5](http://router5.github.io) |
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,34 @@ | ||
{ | ||
"name": "router5-deku", | ||
"version": "0.1.0-alpha.1", | ||
"homepage": "http://router5.github.io", | ||
"authors": [ | ||
"Thomas Roch <thomas.c.roch@gmail.com>" | ||
], | ||
"description": "router5 helpers for Deku", | ||
"main": "dist/browser/router5-deku.js", | ||
"moduleType": [ | ||
"amd", | ||
"es6", | ||
"globals", | ||
"node" | ||
], | ||
"keywords": [ | ||
"router", | ||
"html5", | ||
"history", | ||
"tree", | ||
"deku", | ||
"functional" | ||
], | ||
"license": "MIT", | ||
"ignore": [ | ||
"**/.*", | ||
"node_modules", | ||
"scripts", | ||
"npm-debug.log", | ||
"bower.json", | ||
"README.md", | ||
"package.json" | ||
] | ||
} |
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,85 @@ | ||
import {element} from 'deku' | ||
|
||
// Use of a factory rather than source as having nested routers | ||
// are not excluded | ||
export default linkFactory | ||
|
||
var listeners = {} | ||
|
||
function linkFactory(router) { | ||
let propTypes = { | ||
label: {type: 'string', optional: false}, | ||
button: {type: 'boolean'}, | ||
routeName: {type: 'string', optional: false}, | ||
routeParams: {type: 'object'}, | ||
routeOptions: {type: 'object'}, | ||
activeClassName: {type: 'string'}, | ||
activeStrict: {type: 'function'}, | ||
onClick: {type: 'function'} | ||
} | ||
|
||
let defaultProps = { | ||
activeClassName: 'active', | ||
button: false, | ||
activeStrict: false, | ||
routeParams: {}, | ||
routeOptions: {} | ||
} | ||
|
||
let getInitialState = (props) { | ||
return { | ||
active: router.isActive(props.routeName, props.routeParams, props.activeStrict) | ||
}; | ||
} | ||
|
||
// Is it overkill? | ||
let shouldUpdate = (component, nextProps, nextState) => { | ||
let {state, props} = component | ||
|
||
return !router.areStatesEqual( | ||
{name: nextProps.routeName, params: nextProps.routeParams}, | ||
{name: props.routeName, params: props.routeParams} | ||
) || state.active !== nextState.active; | ||
} | ||
|
||
let render = (component) => { | ||
let {props,state} = component | ||
|
||
} | ||
|
||
let clickHandler = (evt, component, updateState) => { | ||
evt.preventDefault() | ||
|
||
let {props} = component | ||
router.navigate(props.routeName, props.routeParams, props.routeOptions) | ||
} | ||
|
||
let afterMount = (component, el, setState) => { | ||
listeners[component.id] = () => { | ||
let {props} = component.props | ||
setState({active: router.isActive(props.routeName, props.routeParams)}) | ||
} | ||
|
||
router.addListener(listeners[component.id]) | ||
} | ||
|
||
let beforeUnmout = (component, el) => { | ||
router.removeListener(listeners[component.id]) | ||
delete listeners[component.id] | ||
} | ||
|
||
let render = (component, el) => { | ||
let {props, state} = component | ||
let href = router.buildUrl(props.routeName, props.routeParams) | ||
let className = (props.className ? props.className.split(' ') : []) | ||
.concat(state.active ? [props.activeClassName] : []).join(' ') | ||
let onClick = props.onClick || clickHandler | ||
|
||
if (button) { | ||
return element('button', {type: 'button', className, onClick}, [props.label]) | ||
} | ||
return element('a', {href, className, onClick}, [props.label]) | ||
} | ||
|
||
return {propTypes, defaultProps, shouldUpdate, afterMount, beforeUnmout, render} | ||
} |
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,36 @@ | ||
{ | ||
"name": "router5-deku", | ||
"version": "0.1.0-alpha.1", | ||
"description": "router5 helpers for Deku", | ||
"main": "dist/commonjs/index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/router5/router5-deku.git" | ||
}, | ||
"keywords": [ | ||
"router", | ||
"html5", | ||
"history", | ||
"tree", | ||
"deku", | ||
"functional" | ||
], | ||
"author": "Thomas Roch", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/router5/router5-deku/issues" | ||
}, | ||
"homepage": "http://router5.github.io", | ||
"devDependencies": { | ||
"router5": "0.1.0-rc.7", | ||
"async": "^1.3.0", | ||
"uglify-js2": "^2.1.11", | ||
"babel": "^5.6.14" | ||
}, | ||
"peerDependencies": { | ||
"router5": ">=0.1.0-rc.7" | ||
} | ||
} |