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 = {
|
|
|
|
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];
|
|
|
|
},
|
|
|
|
|
|
|
|
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 = {
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
|
|
|
|
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 () {
|
|
|
|
return $location.path();
|
|
|
|
};
|
|
|
|
Location.prototype.go = function (url) {
|
|
|
|
return $location.path(url);
|
|
|
|
};
|