-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See #97.
- Loading branch information
Showing
16 changed files
with
346 additions
and
230 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,3 +1,4 @@ | ||
.idea | ||
node_modules/ | ||
bundle.js | ||
tests/*.jsx |
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
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 |
---|---|---|
@@ -1,72 +1,43 @@ | ||
"use strict"; | ||
|
||
var invariant = require('react/lib/invariant'); | ||
var merge = require('react/lib/merge'); | ||
var mergeInto = require('react/lib/mergeInto'); | ||
|
||
/** | ||
* Create a new route descriptor from a specification. | ||
* | ||
* @param {Object} spec | ||
* @param {?Object} defaults | ||
*/ | ||
function createRoute(spec, defaults) { | ||
|
||
var handler = spec.handler; | ||
var path = spec.path; | ||
var ref = spec.ref; | ||
var matchKeys = spec.matchKeys; | ||
var props = merge({}, spec); | ||
|
||
delete props.path; | ||
delete props.handler; | ||
delete props.ref; | ||
delete props.matchKeys; | ||
|
||
var route = { | ||
path: path, | ||
handler: handler, | ||
props: props, | ||
matchKeys: matchKeys, | ||
ref: ref | ||
}; | ||
|
||
if (defaults) { | ||
mergeInto(route, defaults); | ||
} | ||
|
||
invariant( | ||
typeof route.handler === 'function', | ||
"Route handler should be a component or a function but got: %s", handler | ||
); | ||
|
||
invariant( | ||
route.path !== undefined, | ||
"Route should have an URL pattern specified: %s", handler | ||
); | ||
|
||
return route; | ||
} | ||
|
||
/** | ||
* Regular route descriptor. | ||
* | ||
* @param {Object} spec | ||
*/ | ||
function Route(spec) { | ||
return createRoute(spec); | ||
} | ||
|
||
/** | ||
* Catch all route descriptor. | ||
* | ||
* @param {Object} spec | ||
*/ | ||
function NotFound(spec) { | ||
return createRoute(spec, {path: null}); | ||
var React = require('react'); | ||
|
||
function createClass(name) { | ||
return React.createClass({ | ||
propTypes: { | ||
handler: React.PropTypes.oneOfType([ | ||
React.PropTypes.node, | ||
React.PropTypes.func | ||
]).isRequired, | ||
path: name === 'NotFound' ? | ||
function(props, propName) { | ||
if (props[propName]) throw new Error("Don't pass a `path` to NotFound."); | ||
} | ||
: React.PropTypes.string.isRequired | ||
}, | ||
getDefaultProps: function() { | ||
if (name === 'NotFound') { | ||
return {path: null}; | ||
} | ||
return {}; | ||
}, | ||
render: function() { | ||
throw new Error(name + " is not meant to be directly rendered."); | ||
} | ||
}); | ||
} | ||
|
||
module.exports = { | ||
Route: Route, | ||
NotFound: NotFound | ||
/** | ||
* Regular route descriptor. | ||
* | ||
* @param {Object} spec | ||
*/ | ||
Route: createClass('Route'), | ||
/** | ||
* Catch all route descriptor. | ||
* | ||
* @param {Object} spec | ||
*/ | ||
NotFound: createClass('NotFound') | ||
}; |
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
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.