Comparing version 0.0.3 to 0.0.4
@@ -28,3 +28,3 @@ var util = require('util'), | ||
} | ||
return win.location.hash.substr(1); | ||
return win.location.hash.substr(1) || '/'; | ||
}; | ||
@@ -31,0 +31,0 @@ |
@@ -44,3 +44,4 @@ var CallRouter = require('call').Router, | ||
if (!path) { | ||
this.emit('error', new Error('No path was provided')); | ||
// emit the event asyncronously | ||
setTimeout(this.emit.bind(this, 'error', new Error('No path was provided')), 1); | ||
return false; | ||
@@ -50,3 +51,4 @@ } | ||
if (!callRoute || callRoute instanceof Error) { | ||
this.emit('error', new Error('No route is associated to path: ' + path)); | ||
// emit the event asyncronously | ||
setTimeout(this.emit.bind(this, 'error', new Error('No route is associated to path: ' + path)), 1); | ||
return false; | ||
@@ -70,3 +72,5 @@ } | ||
this.emit('change', eventData); | ||
// emit the event asyncronously | ||
setTimeout(this.emit.bind(this, 'change', eventData), 1); | ||
return true; | ||
@@ -73,0 +77,0 @@ }; |
@@ -7,3 +7,3 @@ { | ||
], | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"dependencies": { | ||
@@ -10,0 +10,0 @@ "call": "2.x.x" |
@@ -35,2 +35,3 @@ var assert = require('assert'), | ||
assert(data.history); | ||
router.removeAllListeners('change'); | ||
done(); | ||
@@ -68,2 +69,3 @@ }; | ||
if (router.getCurrentRoute() === '/fnord') { | ||
router.removeAllListeners('change'); | ||
done(); | ||
@@ -90,2 +92,3 @@ } | ||
if (router.getCurrentRoute() === '/fnord') { | ||
router.removeAllListeners('change'); | ||
done(); | ||
@@ -121,2 +124,3 @@ } | ||
assert(error instanceof Error); | ||
router.removeAllListeners('error'); | ||
done(); | ||
@@ -133,2 +137,3 @@ }); | ||
assert(error instanceof Error); | ||
router.removeAllListeners('error'); | ||
done(); | ||
@@ -154,2 +159,3 @@ }); | ||
if (router.getCurrentRoute() === '/fnord') { | ||
router.removeAllListeners('change'); | ||
done(); | ||
@@ -185,4 +191,8 @@ } | ||
router.initialize({ routes: ['/', '/fnord'], useHash: false, root: '/', _window: mockWindow }); | ||
assert(!router.back()); | ||
done(); | ||
router.on('change', function() { | ||
router.removeAllListeners('change'); | ||
assert(!router.back()); | ||
done(); | ||
}); | ||
}); | ||
@@ -198,3 +208,8 @@ | ||
assert(data.history); | ||
// simulate browser behavior when path changes | ||
mockWindow.onpopstate(); | ||
if (lastRoute === '/fnord' && router.getCurrentRoute() === '/') { | ||
router.removeAllListeners('change'); | ||
done(); | ||
@@ -208,14 +223,4 @@ } | ||
// simulate browser behavior when path changes | ||
mockWindow.onpopstate(); | ||
router.go('/fnord'); | ||
// simulate browser behavior when path changes | ||
mockWindow.onpopstate(); | ||
assert(router.back()); | ||
// simulate browser behavior when path changes | ||
mockWindow.onpopstate(); | ||
setTimeout(router.go.bind(router, '/fnord'), 25); | ||
setTimeout(router.back.bind(router), 50); | ||
}); | ||
@@ -222,0 +227,0 @@ }); |
27274
634