Created
August 2, 2016 18:00
-
-
Save christopherthielen/c606d3e6b056ee1ae2a57e570d5d3c55 to your computer and use it in GitHub Desktop.
otherwise thinggy
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
class OtherwiseRouterProvider { | |
constructor($urlRouterProvider) { | |
this.otherwiseRouters = []; | |
this.$urlRouterProvider = $urlRouterProvider; | |
} | |
registerRouter(func) { | |
this.otherwiseRouters.unshift(func); | |
return this; | |
} | |
$get($injector) { | |
let service = new OtherwiseRouter(this.otherwiseRouters); | |
this.$urlRouterProvider.otherwise(($injector, $location) => { | |
return service.route($location.path()); | |
}); | |
return service; | |
} | |
} | |
class OtherwiseRouter { | |
constructor(otherwiseRouters) { | |
this.otherwiseRouters = otherwiseRouters; | |
} | |
getRouters() { | |
return this.otherwiseRouters; | |
} | |
route(path) { | |
this.otherwiseRouters.forEach(function(router) { | |
router(); | |
}, this); | |
} | |
} | |
OtherwiseRouterProvider.$inject = ['$injector']; | |
export {OtherwiseRouterProvider, OtherwiseRouter}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment