Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/statico/route.js
JavaScript Inversion of Control container for URIs - location.hash navigation goodness
https://github.com/statico/route.js
Last synced: 4 days ago
JSON representation
JavaScript Inversion of Control container for URIs - location.hash navigation goodness
- Host: GitHub
- URL: https://github.com/statico/route.js
- Owner: statico
- Created: 2011-03-01T06:40:37.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2010-07-28T04:56:09.000Z (over 14 years ago)
- Last Synced: 2024-05-02T06:02:00.861Z (6 months ago)
- Language: JavaScript
- Homepage: http://maraksquires.com/route.js/
- Size: 107 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: ReadMe.md
Awesome Lists containing this project
README
/***********************************************************************
route.js enables you to create "routes" based on a unique path
a route can be considered a unique state
a route may have multiple functions bound to them
a route can be triggered by calling route('/foo').run()
*** http://en.wikipedia.org/wiki/Inversion_of_control ***
*** "Don't call us, we'll call you" ***USAGE:
route('#/account').bind(customMethod);
route('#/account').bind(customMethod2);
route('#/websites').bind(customMethod);
route('#/websites').bind(function(){
alert('custom closure');
});
route('#/account').run();
route('#/websites').run();WHERE THE ROUTES AT?
All routes are stored globally in window['routes']
console.log(window['routes']);ROUTE PATTERN MATCHING (aka Sinatra routing):
add docs here
ASPECTS OF THE ROUTE (aka Apsect Oriented Programming)
var myBefore = function(){
alert('before()');
};
var myAfter = function(){
alert('after()');
};
var myExit= function(){
alert('exit()');
};route('#/Learn/:topic').before(myBefore);
route('#/Learn/:topic').after(myAfter);
route('#/Learn/:topic').exit(myExit);PROTIP: Use a Dispatcher!
var Biggie={};
Biggie._hashchange_last = '';
Biggie._onhashchange=function(){
if(Biggie._hashchange_last!=location.hash){
Biggie._hashchange_last=location.hash;
route(location.hash).run();
}
}setInterval(function () {Biggie._onhashchange();}, 50);
Now, instead of calling route('#/websites').run() directly
you could simply modify the location.hash to #/websites and
the route would trigger its events!*************************************************************************/