refactor(angular_1_router): use directives for route targets

BREAKING CHANGE:

Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:

```
$route.config([
  { route: '/', component: MyController }
])
```

Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.

To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:

```
$route.config([
  { route: '/', component: 'myDirective' }
])
```

BREAKING CHANGE:

In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:

```
MyController.prototype.onActivate = ...
```

After:

```
MyController.prototype.$onActivate = ...
```

Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
This commit is contained in:
Brian Ford
2015-09-18 15:53:50 -07:00
parent 6e0ca7f39a
commit 5205a9e65f
12 changed files with 547 additions and 724 deletions

View File

@ -32,6 +32,10 @@ function isArray(obj) {
return Array.isArray(obj);
}
function getTypeNameForDebugging (fn) {
return fn.name || 'Root';
}
var PromiseWrapper = {
resolve: function (reason) {
return $q.when(reason);
@ -251,8 +255,8 @@ var StringWrapper = {
return s.replace(from, replace);
},
startsWith: function(s, start) {
return s.startsWith(start);
startsWith: function(s, start) {
return s.substr(0, start.length) === start;
},
replaceAllMapped: function(s, from, cb) {
@ -272,14 +276,18 @@ var StringWrapper = {
//TODO: implement?
// I think it's too heavy to ask 1.x users to bring in Rx for the router...
function EventEmitter() {
}
function EventEmitter() {}
var BaseException = Error;
var ObservableWrapper = {
callNext: function(){}
callNext: function(ob, val) {
ob.fn(val);
},
subscribe: function(ob, fn) {
ob.fn = fn;
}
};
// TODO: https://github.com/angular/angular.js/blob/master/src/ng/browser.js#L227-L265