2015-08-20 16:19:34 -04:00
|
|
|
function CONST() {
|
|
|
|
return (function(target) {
|
|
|
|
return target;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function CONST_EXPR(expr) {
|
|
|
|
return expr;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isPresent (x) {
|
|
|
|
return !!x;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isBlank (x) {
|
|
|
|
return !x;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isString(obj) {
|
|
|
|
return typeof obj === 'string';
|
|
|
|
}
|
|
|
|
|
|
|
|
function isType (x) {
|
|
|
|
return typeof x === 'function';
|
|
|
|
}
|
|
|
|
|
|
|
|
function isStringMap(obj) {
|
|
|
|
return typeof obj === 'object' && obj !== null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isArray(obj) {
|
|
|
|
return Array.isArray(obj);
|
|
|
|
}
|
|
|
|
|
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.
2015-09-18 18:53:50 -04:00
|
|
|
function getTypeNameForDebugging (fn) {
|
|
|
|
return fn.name || 'Root';
|
|
|
|
}
|
|
|
|
|
2015-08-20 16:19:34 -04:00
|
|
|
var PromiseWrapper = {
|
|
|
|
resolve: function (reason) {
|
|
|
|
return $q.when(reason);
|
|
|
|
},
|
|
|
|
|
|
|
|
reject: function (reason) {
|
|
|
|
return $q.reject(reason);
|
|
|
|
},
|
|
|
|
|
|
|
|
catchError: function (promise, fn) {
|
|
|
|
return promise.then(null, fn);
|
|
|
|
},
|
|
|
|
all: function (promises) {
|
|
|
|
return $q.all(promises);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var RegExpWrapper = {
|
|
|
|
create: function(regExpStr, flags) {
|
|
|
|
flags = flags ? flags.replace(/g/g, '') : '';
|
|
|
|
return new RegExp(regExpStr, flags + 'g');
|
|
|
|
},
|
|
|
|
firstMatch: function(regExp, input) {
|
|
|
|
regExp.lastIndex = 0;
|
|
|
|
return regExp.exec(input);
|
|
|
|
},
|
|
|
|
matcher: function (regExp, input) {
|
|
|
|
regExp.lastIndex = 0;
|
|
|
|
return { re: regExp, input: input };
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var reflector = {
|
|
|
|
annotations: function (fn) {
|
|
|
|
//TODO: implement me
|
|
|
|
return fn.annotations || [];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var MapWrapper = {
|
|
|
|
create: function() {
|
|
|
|
return new Map();
|
|
|
|
},
|
|
|
|
|
|
|
|
get: function(m, k) {
|
|
|
|
return m.get(k);
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function(m, k, v) {
|
|
|
|
return m.set(k, v);
|
|
|
|
},
|
|
|
|
|
|
|
|
contains: function (m, k) {
|
|
|
|
return m.has(k);
|
|
|
|
},
|
|
|
|
|
|
|
|
forEach: function (m, fn) {
|
|
|
|
return m.forEach(fn);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var StringMapWrapper = {
|
|
|
|
create: function () {
|
|
|
|
return {};
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (m, k, v) {
|
|
|
|
return m[k] = v;
|
|
|
|
},
|
|
|
|
|
|
|
|
get: function (m, k) {
|
|
|
|
return m.hasOwnProperty(k) ? m[k] : undefined;
|
|
|
|
},
|
|
|
|
|
|
|
|
contains: function (m, k) {
|
|
|
|
return m.hasOwnProperty(k);
|
|
|
|
},
|
|
|
|
|
|
|
|
keys: function(map) {
|
|
|
|
return Object.keys(map);
|
|
|
|
},
|
|
|
|
|
|
|
|
isEmpty: function(map) {
|
|
|
|
for (var prop in map) {
|
|
|
|
if (map.hasOwnProperty(prop)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
delete: function(map, key) {
|
|
|
|
delete map[key];
|
|
|
|
},
|
|
|
|
|
|
|
|
forEach: function (m, fn) {
|
2015-09-11 19:00:26 -04:00
|
|
|
for (var prop in m) {
|
2015-08-20 16:19:34 -04:00
|
|
|
if (m.hasOwnProperty(prop)) {
|
|
|
|
fn(m[prop], prop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
equals: function (m1, m2) {
|
|
|
|
var k1 = Object.keys(m1);
|
|
|
|
var k2 = Object.keys(m2);
|
|
|
|
if (k1.length != k2.length) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
var key;
|
|
|
|
for (var i = 0; i < k1.length; i++) {
|
|
|
|
key = k1[i];
|
|
|
|
if (m1[key] !== m2[key]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
merge: function(m1, m2) {
|
|
|
|
var m = {};
|
|
|
|
for (var attr in m1) {
|
|
|
|
if (m1.hasOwnProperty(attr)) {
|
|
|
|
m[attr] = m1[attr];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (var attr in m2) {
|
|
|
|
if (m2.hasOwnProperty(attr)) {
|
|
|
|
m[attr] = m2[attr];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var List = Array;
|
|
|
|
var ListWrapper = {
|
2016-02-01 05:05:20 -05:00
|
|
|
toJSON: function(l) {
|
|
|
|
return JSON.stringify(l);
|
|
|
|
},
|
|
|
|
|
refactor(router): improve recognition and generation pipeline
This is a big change. @matsko also deserves much of the credit for the implementation.
Previously, `ComponentInstruction`s held all the state for async components.
Now, we introduce several subclasses for `Instruction` to describe each type of navigation.
BREAKING CHANGE:
Redirects now use the Link DSL syntax. Before:
```
@RouteConfig([
{ path: '/foo', redirectTo: '/bar' },
{ path: '/bar', component: BarCmp }
])
```
After:
```
@RouteConfig([
{ path: '/foo', redirectTo: ['Bar'] },
{ path: '/bar', component: BarCmp, name: 'Bar' }
])
```
BREAKING CHANGE:
This also introduces `useAsDefault` in the RouteConfig, which makes cases like lazy-loading
and encapsulating large routes with sub-routes easier.
Previously, you could use `redirectTo` like this to expand a URL like `/tab` to `/tab/posts`:
@RouteConfig([
{ path: '/tab', redirectTo: '/tab/users' }
{ path: '/tab', component: TabsCmp, name: 'Tab' }
])
AppCmp { ... }
Now the recommended way to handle this is case is to use `useAsDefault` like so:
```
@RouteConfig([
{ path: '/tab', component: TabsCmp, name: 'Tab' }
])
AppCmp { ... }
@RouteConfig([
{ path: '/posts', component: PostsCmp, useAsDefault: true, name: 'Posts' },
{ path: '/users', component: UsersCmp, name: 'Users' }
])
TabsCmp { ... }
```
In the above example, you can write just `['/Tab']` and the route `Users` is automatically selected as a child route.
Closes #4728
Closes #4228
Closes #4170
Closes #4490
Closes #4694
Closes #5200
Closes #5475
2015-11-23 21:07:37 -05:00
|
|
|
clear: function (l) {
|
|
|
|
l.length = 0;
|
|
|
|
},
|
|
|
|
|
2015-08-20 16:19:34 -04:00
|
|
|
create: function () {
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
|
|
|
|
push: function (l, v) {
|
|
|
|
return l.push(v);
|
|
|
|
},
|
|
|
|
|
|
|
|
forEach: function (l, fn) {
|
|
|
|
return l.forEach(fn);
|
|
|
|
},
|
|
|
|
|
|
|
|
first: function(array) {
|
|
|
|
if (!array)
|
|
|
|
return null;
|
|
|
|
return array[0];
|
|
|
|
},
|
|
|
|
|
2015-12-07 13:51:01 -05:00
|
|
|
last: function(array) {
|
|
|
|
return (array && array.length) > 0 ? array[array.length - 1] : null;
|
|
|
|
},
|
|
|
|
|
2015-08-20 16:19:34 -04:00
|
|
|
map: function (l, fn) {
|
|
|
|
return l.map(fn);
|
|
|
|
},
|
|
|
|
|
|
|
|
join: function (l, str) {
|
|
|
|
return l.join(str);
|
|
|
|
},
|
|
|
|
|
|
|
|
reduce: function(list, fn, init) {
|
|
|
|
return list.reduce(fn, init);
|
|
|
|
},
|
|
|
|
|
|
|
|
filter: function(array, pred) {
|
|
|
|
return array.filter(pred);
|
|
|
|
},
|
|
|
|
|
|
|
|
concat: function(a, b) {
|
|
|
|
return a.concat(b);
|
|
|
|
},
|
|
|
|
|
|
|
|
slice: function(l) {
|
|
|
|
var from = arguments[1] !== (void 0) ? arguments[1] : 0;
|
|
|
|
var to = arguments[2] !== (void 0) ? arguments[2] : null;
|
|
|
|
return l.slice(from, to === null ? undefined : to);
|
|
|
|
},
|
|
|
|
|
|
|
|
maximum: function(list, predicate) {
|
|
|
|
if (list.length == 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
var solution = null;
|
|
|
|
var maxValue = -Infinity;
|
|
|
|
for (var index = 0; index < list.length; index++) {
|
|
|
|
var candidate = list[index];
|
|
|
|
if (isBlank(candidate)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
var candidateValue = predicate(candidate);
|
|
|
|
if (candidateValue > maxValue) {
|
|
|
|
solution = candidate;
|
|
|
|
maxValue = candidateValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return solution;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var StringWrapper = {
|
2016-02-01 05:05:20 -05:00
|
|
|
charCodeAt: function(s, i) {
|
|
|
|
return s.charCodeAt(i);
|
|
|
|
},
|
|
|
|
|
2015-08-20 16:19:34 -04:00
|
|
|
equals: function (s1, s2) {
|
|
|
|
return s1 === s2;
|
|
|
|
},
|
|
|
|
|
|
|
|
split: function(s, re) {
|
|
|
|
return s.split(re);
|
|
|
|
},
|
|
|
|
|
|
|
|
replaceAll: function(s, from, replace) {
|
|
|
|
return s.replace(from, replace);
|
|
|
|
},
|
|
|
|
|
|
|
|
replaceAllMapped: function(s, from, cb) {
|
|
|
|
return s.replace(from, function(matches) {
|
|
|
|
// Remove offset & string from the result array
|
|
|
|
matches.splice(-2, 2);
|
|
|
|
// The callback receives match, p1, ..., pn
|
|
|
|
return cb.apply(null, matches);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
contains: function(s, substr) {
|
|
|
|
return s.indexOf(substr) != -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
//TODO: implement?
|
|
|
|
// I think it's too heavy to ask 1.x users to bring in Rx for the router...
|
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.
2015-09-18 18:53:50 -04:00
|
|
|
function EventEmitter() {}
|
2015-08-20 16:19:34 -04:00
|
|
|
|
|
|
|
var BaseException = Error;
|
|
|
|
|
|
|
|
var ObservableWrapper = {
|
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.
2015-09-18 18:53:50 -04:00
|
|
|
callNext: function(ob, val) {
|
|
|
|
ob.fn(val);
|
|
|
|
},
|
2015-11-16 02:58:59 -05:00
|
|
|
callEmit: function(ob, val) {
|
|
|
|
ob.fn(val);
|
|
|
|
},
|
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.
2015-09-18 18:53:50 -04:00
|
|
|
|
|
|
|
subscribe: function(ob, fn) {
|
|
|
|
ob.fn = fn;
|
|
|
|
}
|
2015-08-20 16:19:34 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// TODO: https://github.com/angular/angular.js/blob/master/src/ng/browser.js#L227-L265
|
|
|
|
var $__router_47_location__ = {
|
|
|
|
Location: Location
|
|
|
|
};
|
|
|
|
|
|
|
|
function Location(){}
|
|
|
|
Location.prototype.subscribe = function () {
|
|
|
|
//TODO: implement
|
|
|
|
};
|
|
|
|
Location.prototype.path = function () {
|
2016-01-26 07:51:50 -05:00
|
|
|
return $location.url();
|
2015-08-20 16:19:34 -04:00
|
|
|
};
|
2016-04-07 20:02:07 -04:00
|
|
|
Location.prototype.isCurrentPathEqualTo = function (path, query) {
|
|
|
|
if (query === void 0) { query = ''; }
|
|
|
|
return this.path() === (path + query);
|
|
|
|
};
|
2016-01-26 07:51:50 -05:00
|
|
|
Location.prototype.go = function (path, query) {
|
|
|
|
return $location.url(path + query);
|
2015-08-20 16:19:34 -04:00
|
|
|
};
|
2016-04-07 20:02:07 -04:00
|
|
|
Location.prototype.replaceState = function (path, query) {
|
|
|
|
if (query === void 0) { query = ''; }
|
|
|
|
$location.url(path + query);
|
|
|
|
$location.replace();
|
|
|
|
};
|
2016-03-04 03:14:27 -05:00
|
|
|
Location.prototype.prepareExternalUrl = function(url) {
|
|
|
|
if (url.length > 0 && !url.startsWith('/')) {
|
|
|
|
url = '/' + url;
|
|
|
|
}
|
2016-03-21 07:49:37 -04:00
|
|
|
return $location.$$html5 ? '.' + url : '#' + $locationHashPrefix + url;
|
2016-03-04 03:14:27 -05:00
|
|
|
};
|