HipsterHistory
class
class HipsterHistory {
static List _routes;
static get routes() {
if (_routes == null) _routes = [];
return _routes;
}
static route(route, fn) {
routes.add([route, fn]);
}
static startHistory() {
window.on.popState.add(_checkUrl);
}
static _checkUrl(_) {
var fragment = window.location.hash.replaceFirst('#', '');
var matching_handlers = routes.
filter((r) => r[0].hasMatch(fragment));
if (matching_handlers.isEmpty()) return;
var handler = matching_handlers[0];
handler[1](fragment);
}
}
Static Properties
final routes #
static get routes() {
if (_routes == null) _routes = [];
return _routes;
}
Static Methods
route(route, fn) #
static route(route, fn) {
routes.add([route, fn]);
}
startHistory() #
static startHistory() {
window.on.popState.add(_checkUrl);
}