Skip to content
Browse files

changes from testing navigation/Router

  • Loading branch information...
1 parent 67b6c3b commit b35871bec7d8d36d30a46a9c9be6833bfaec0788 @neonstalwart neonstalwart committed
Showing with 19 additions and 5 deletions.
  1. +13 −5 navigation/Router.js
  2. +6 −0 util/error.js
View
18 navigation/Router.js
@@ -15,13 +15,17 @@
define([
'../support/array',
'../support/compose',
- '../support/promise'
-], function (arr, compose, promise) {
+ '../support/promise',
+ '../util/error'
+], function (arr, compose, promise, error) {
'use strict';
+
// this is used as an event listener component
- return compose(function NavigationRouter() {
+ function NavigationRouter() {
this._routes = [];
- }, {
+ }
+
+ return compose(NavigationRouter, {
execute: function (event) {
var router = this,
target = event.target;
@@ -40,11 +44,15 @@ define([
if (args) {
args.unshift(event);
- return route.handler.apply(null, args);
+ return route.handler.apply(null, args) || event;
}
},
addRoute: function (route, handler) {
+ if (typeof handler !== 'function') {
+ throw new error.MissingHandler(route);
+ }
+
var router = this,
routes = router._routes,
lastEvent = router.lastEvent,
View
6 util/error.js
@@ -30,6 +30,11 @@ define(['../support/compose'], function (compose) {
this.message = 'Model with id "' + model.id + '" needs a lifecycle.';
}
+ function MissingHandler(route) {
+ this.route = route;
+ this.message = 'Missing/Invalid handler function for route - ' + route;
+ }
+
function ContainerDestroyed(container) {
this.message = 'Container "' + container.name + ' has been destroyed.';
}
@@ -49,6 +54,7 @@ define(['../support/compose'], function (compose) {
DuplicateFiber: compose(Error, DuplicateFiber),
MissingId: compose(Error, MissingId),
MissingLifecycle: compose(Error, MissingLifecycle),
+ MissingHandler: compose(Error, MissingHandler),
ContainerDestroyed: compose(Error, ContainerDestroyed),
DuplicateModel: compose(Error, DuplicateModel),
DuplicateServiceModel: compose(Error, DuplicateServiceModel)

0 comments on commit b35871b

Please sign in to comment.
Something went wrong with that request. Please try again.