├── .editorconfig ├── .gitattributes ├── .gitignore ├── .travis.yml ├── angular2-polyfill ├── .npmignore ├── bundles │ ├── angular2-polyfill.d.ts │ └── angular2-polyfill.js ├── core.ts ├── http.ts ├── package.json ├── platform │ ├── browser.ts │ └── upgrade.ts ├── router-deprecated.ts ├── src │ ├── common │ │ ├── common.ts │ │ └── pipes │ │ │ └── async.pipe.ts │ ├── core │ │ ├── classes │ │ │ ├── event_emitter.ts │ │ │ ├── injector.ts │ │ │ ├── opaque_token.ts │ │ │ └── provider.ts │ │ ├── core.ts │ │ ├── decorators │ │ │ ├── Component.ts │ │ │ ├── Directive.ts │ │ │ ├── Inject.ts │ │ │ ├── Injectable.ts │ │ │ ├── Input.ts │ │ │ ├── Optional.ts │ │ │ ├── Output.ts │ │ │ └── Pipe.ts │ │ ├── functions │ │ │ └── provide.ts │ │ └── interfaces │ │ │ ├── ComponentMetadata.ts │ │ │ ├── DirectiveMetadata.ts │ │ │ ├── OnDestroy.ts │ │ │ ├── OnInit.ts │ │ │ ├── PipeMetadata.ts │ │ │ ├── PipeTransform.ts │ │ │ └── ProviderMetadata.ts │ ├── http │ │ ├── http.service.ts │ │ ├── interfaces │ │ │ ├── RequestOptionsArgs.ts │ │ │ └── Response.ts │ │ └── providers.ts │ ├── platform │ │ ├── bootstrap │ │ │ ├── component.ts │ │ │ ├── core.ts │ │ │ ├── directive.ts │ │ │ ├── factory.ts │ │ │ ├── index.ts │ │ │ ├── injectable.ts │ │ │ ├── multi.ts │ │ │ ├── pipe.ts │ │ │ ├── provider.ts │ │ │ └── value.ts │ │ ├── upgrade.ts │ │ └── utils │ │ │ ├── host.ts │ │ │ ├── injector.ts │ │ │ ├── input.ts │ │ │ └── output.ts │ ├── router-deprecated │ │ ├── decorators │ │ │ └── RouteConfig.ts │ │ ├── instruction.ts │ │ ├── interfaces.ts │ │ ├── lifecycle │ │ │ └── lifecycle_annotations.ts │ │ ├── providers.ts │ │ └── router.ts │ └── utils.ts ├── tsconfig.json ├── tsd.json └── typings.json ├── gulpfile.js ├── license ├── package.json ├── readme.md ├── test ├── core │ └── classes │ │ └── opaque_token.js └── platform │ └── utils │ ├── fixtures │ ├── reflect.js │ ├── scope.js │ └── utils.js │ ├── host-parsing.js │ ├── input-binding.js │ └── output-binding.js └── tsconfig.json /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [{package.json,*.yml}] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | typings 3 | .vscode 4 | .idea 5 | **/*.js 6 | **/*.js.map 7 | **/*.d.ts 8 | 9 | # Copied by the build process 10 | angular2-polyfill/readme.md 11 | 12 | # Do not ignore these files 13 | !gulpfile.js 14 | !angular2-polyfill/bundles/**/*.js 15 | !angular2-polyfill/bundles/**/*.d.ts 16 | !test/**/*.js 17 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - '5' 5 | -------------------------------------------------------------------------------- /angular2-polyfill/.npmignore: -------------------------------------------------------------------------------- 1 | # Directories 2 | node_modules 3 | typings 4 | 5 | # Dot files 6 | .npmignore 7 | 8 | # d.ts files 9 | **/*.d.ts 10 | -------------------------------------------------------------------------------- /angular2-polyfill/bundles/angular2-polyfill.d.ts: -------------------------------------------------------------------------------- 1 | declare module "angular2-polyfill/src/core/interfaces/ComponentMetadata" { 2 | export interface ComponentMetadata { 3 | selector?: string; 4 | inputs?: string[]; 5 | outputs?: string[]; 6 | host?: { 7 | [key: string]: string; 8 | }; 9 | exportAs?: string; 10 | template?: string; 11 | templateUrl?: string; 12 | styles?: string[]; 13 | styleUrls?: string[]; 14 | directives?: any[]; 15 | providers?: any[]; 16 | pipes?: any[]; 17 | } 18 | } 19 | declare module "angular2-polyfill/src/utils" { 20 | /** 21 | * Helper functions 22 | */ 23 | export function annotate(target: any, key: any, value: any): void; 24 | export function toInjectorName(token: any): any; 25 | } 26 | declare module "angular2-polyfill/src/core/decorators/Component" { 27 | import { ComponentMetadata } from "angular2-polyfill/src/core/interfaces/ComponentMetadata"; 28 | export function Component(component: ComponentMetadata): (target: any) => void; 29 | } 30 | declare module "angular2-polyfill/src/core/interfaces/DirectiveMetadata" { 31 | export interface DirectiveMetadata { 32 | selector?: string; 33 | inputs?: string[]; 34 | outputs?: string[]; 35 | host?: { 36 | [key: string]: string; 37 | }; 38 | providers?: any[]; 39 | } 40 | } 41 | declare module "angular2-polyfill/src/core/decorators/Directive" { 42 | import { DirectiveMetadata } from "angular2-polyfill/src/core/interfaces/DirectiveMetadata"; 43 | export function Directive(options: DirectiveMetadata): (target: any) => void; 44 | } 45 | declare module "angular2-polyfill/src/core/decorators/Inject" { 46 | export function Inject(token: any): (target: any, propertyKey: string | symbol, parameterIndex: number) => void; 47 | } 48 | declare module "angular2-polyfill/src/core/decorators/Injectable" { 49 | export function Injectable(): (target: any) => void; 50 | } 51 | declare module "angular2-polyfill/src/core/decorators/Input" { 52 | export function Input(bindingPropertyName?: string): (target: any, propertyKey: string) => void; 53 | } 54 | declare module "angular2-polyfill/src/core/decorators/Output" { 55 | export function Output(bindingPropertyName?: string): (target: any, propertyKey: string) => void; 56 | } 57 | declare module "angular2-polyfill/src/core/interfaces/PipeMetadata" { 58 | export interface PipeMetadata { 59 | name: string; 60 | pure?: boolean; 61 | } 62 | } 63 | declare module "angular2-polyfill/src/core/decorators/Pipe" { 64 | import { PipeMetadata } from "angular2-polyfill/src/core/interfaces/PipeMetadata"; 65 | export function Pipe(pipe: PipeMetadata): (target: any) => void; 66 | } 67 | declare module "angular2-polyfill/src/core/decorators/Optional" { 68 | export function Optional(): (target: any, propertyKey: string | symbol, parameterIndex: number) => void; 69 | } 70 | declare module "angular2-polyfill/src/core/interfaces/ProviderMetadata" { 71 | export interface ProviderMetadata { 72 | useClass?: any; 73 | useValue?: any; 74 | useExisting?: any; 75 | useFactory?: Function; 76 | deps?: any[]; 77 | multi?: boolean; 78 | } 79 | } 80 | declare module "angular2-polyfill/src/core/functions/provide" { 81 | import { Provider } from "angular2-polyfill/src/core/core"; 82 | import { ProviderMetadata } from "angular2-polyfill/src/core/interfaces/ProviderMetadata"; 83 | export function provide(token: any, options: ProviderMetadata): Provider; 84 | } 85 | declare module "angular2-polyfill/src/core/classes/provider" { 86 | import { ProviderMetadata } from "angular2-polyfill/src/core/interfaces/ProviderMetadata"; 87 | export class Provider { 88 | token: any; 89 | useClass: any; 90 | useValue: any; 91 | useExisting: any; 92 | useFactory: Function; 93 | deps: any[]; 94 | multi: boolean; 95 | constructor(token: any, options: ProviderMetadata); 96 | } 97 | } 98 | declare module "angular2-polyfill/src/core/classes/opaque_token" { 99 | export class OpaqueToken { 100 | private _desc; 101 | constructor(_desc: string); 102 | toString(): string; 103 | } 104 | } 105 | declare module "angular2-polyfill/src/core/classes/injector" { 106 | export class Injector { 107 | private _injector; 108 | constructor(); 109 | get(token: any): {}; 110 | getOptional(token: any): {}; 111 | } 112 | } 113 | declare module "angular2-polyfill/src/core/classes/event_emitter" { 114 | import { Subject } from 'rxjs'; 115 | export class EventEmitter extends Subject { 116 | private _isAsync; 117 | constructor(isAsync?: boolean); 118 | emit(value: T): void; 119 | /** 120 | * @deprecated - use .emit(value) instead 121 | */ 122 | next(value: any): void; 123 | subscribe(generatorOrNext?: any, error?: any, complete?: any): any; 124 | } 125 | } 126 | declare module "angular2-polyfill/src/core/interfaces/OnInit" { 127 | export interface OnInit { 128 | ngOnInit(): void; 129 | } 130 | } 131 | declare module "angular2-polyfill/src/core/interfaces/OnDestroy" { 132 | export interface OnDestroy { 133 | ngOnDestroy(): void; 134 | } 135 | } 136 | declare module "angular2-polyfill/src/core/interfaces/PipeTransform" { 137 | export interface PipeTransform { 138 | transform(value: any, args: any[]): any; 139 | } 140 | } 141 | declare module "angular2-polyfill/src/core/core" { 142 | export { Component } from "angular2-polyfill/src/core/decorators/Component"; 143 | export { Directive } from "angular2-polyfill/src/core/decorators/Directive"; 144 | export { Inject } from "angular2-polyfill/src/core/decorators/Inject"; 145 | export { Injectable } from "angular2-polyfill/src/core/decorators/Injectable"; 146 | export { Input } from "angular2-polyfill/src/core/decorators/Input"; 147 | export { Output } from "angular2-polyfill/src/core/decorators/Output"; 148 | export { Pipe } from "angular2-polyfill/src/core/decorators/Pipe"; 149 | export { Optional } from "angular2-polyfill/src/core/decorators/Optional"; 150 | export { provide } from "angular2-polyfill/src/core/functions/provide"; 151 | export { Provider } from "angular2-polyfill/src/core/classes/provider"; 152 | export { Injector } from "angular2-polyfill/src/core/classes/injector"; 153 | export { OpaqueToken } from "angular2-polyfill/src/core/classes/opaque_token"; 154 | export { EventEmitter } from "angular2-polyfill/src/core/classes/event_emitter"; 155 | export { OnInit } from "angular2-polyfill/src/core/interfaces/OnInit"; 156 | export { OnDestroy } from "angular2-polyfill/src/core/interfaces/OnDestroy"; 157 | export { PipeTransform } from "angular2-polyfill/src/core/interfaces/PipeTransform"; 158 | } 159 | declare module "angular2-polyfill/core" { 160 | export * from "angular2-polyfill/src/core/core"; 161 | } 162 | declare module "angular2-polyfill/src/http/interfaces/RequestOptionsArgs" { 163 | export interface RequestOptionsArgs { 164 | params?: string | any; 165 | data?: string | any; 166 | headers?: any; 167 | xsrfHeaderName?: string; 168 | xsrfCookieName?: string; 169 | transformRequest?: Function | Function[]; 170 | transformResponse?: Function | Function[]; 171 | paramSerializer?: string | Function; 172 | cache?: boolean | any; 173 | timeout?: number | Promise; 174 | withCredentials?: boolean; 175 | responseType?: string; 176 | } 177 | } 178 | declare module "angular2-polyfill/src/http/interfaces/Response" { 179 | import { RequestOptionsArgs } from "angular2-polyfill/src/http/interfaces/RequestOptionsArgs"; 180 | export interface Response { 181 | data: string | any; 182 | status: number; 183 | headers: Function; 184 | config: RequestOptionsArgs; 185 | statusText: string; 186 | } 187 | } 188 | declare module "angular2-polyfill/src/http/http.service" { 189 | import { Observable } from 'rxjs'; 190 | import { RequestOptionsArgs } from "angular2-polyfill/src/http/interfaces/RequestOptionsArgs"; 191 | import { Response } from "angular2-polyfill/src/http/interfaces/Response"; 192 | export class Http { 193 | private http; 194 | constructor(http: any); 195 | get(url: string, options?: RequestOptionsArgs): Observable; 196 | post(url: string, body: any, options?: RequestOptionsArgs): Observable; 197 | put(url: string, body: any, options?: RequestOptionsArgs): Observable; 198 | delete(url: string, options?: RequestOptionsArgs): Observable; 199 | patch(url: string, body: any, options?: RequestOptionsArgs): Observable; 200 | head(url: string, options?: RequestOptionsArgs): Observable; 201 | } 202 | } 203 | declare module "angular2-polyfill/src/http/providers" { 204 | import { Http } from "angular2-polyfill/src/http/http.service"; 205 | export const HTTP_PROVIDERS: typeof Http[]; 206 | } 207 | declare module "angular2-polyfill/http" { 208 | export { Http } from "angular2-polyfill/src/http/http.service"; 209 | export { HTTP_PROVIDERS } from "angular2-polyfill/src/http/providers"; 210 | } 211 | declare module "angular2-polyfill/src/router/instruction" { 212 | export class RouteParams { 213 | private stateParams; 214 | constructor(stateParams: any); 215 | get(param: string): string; 216 | } 217 | export class Instruction { 218 | _state: string; 219 | urlPath: string; 220 | urlParams: string; 221 | } 222 | } 223 | declare module "angular2-polyfill/src/router/router" { 224 | import { Instruction } from "angular2-polyfill/src/router/instruction"; 225 | export class Router { 226 | private state; 227 | constructor(state: any); 228 | isRouteActive(instruction: Instruction): boolean; 229 | navigate(linkParams: any[]): Promise; 230 | renavigate(): Promise; 231 | generate(linkParams: any[]): Promise; 232 | } 233 | } 234 | declare module "angular2-polyfill/src/router/interfaces" { 235 | export interface RouteDefinition { 236 | path?: string; 237 | component?: any; 238 | as?: string; 239 | name?: string; 240 | useAsDefault?: boolean; 241 | } 242 | } 243 | declare module "angular2-polyfill/src/router/decorators/RouteConfig" { 244 | import { RouteDefinition } from "angular2-polyfill/src/router/interfaces"; 245 | export function RouteConfig(routes: RouteDefinition[]): (target: any) => void; 246 | } 247 | declare module "angular2-polyfill/src/router/lifecycle/lifecycle_annotations" { 248 | import { Instruction } from "angular2-polyfill/src/router/instruction"; 249 | export function CanActivate(hook: Function | ((next: Instruction, prev: Instruction) => Promise | boolean)): (target: any) => void; 250 | export interface CanActivate { 251 | routerCanActivate(next: Instruction, prev: Instruction): Promise | boolean; 252 | } 253 | } 254 | declare module "angular2-polyfill/src/router/providers" { 255 | import { Router } from "angular2-polyfill/src/router/router"; 256 | import { RouteParams } from "angular2-polyfill/src/router/instruction"; 257 | export const ROUTER_PROVIDERS: (typeof Router | typeof RouteParams)[]; 258 | } 259 | declare module "angular2-polyfill/router" { 260 | export { Router } from "angular2-polyfill/src/router/router"; 261 | export { RouteParams } from "angular2-polyfill/src/router/instruction"; 262 | export { Instruction } from "angular2-polyfill/src/router/instruction"; 263 | export { RouteConfig } from "angular2-polyfill/src/router/decorators/RouteConfig"; 264 | export { CanActivate } from "angular2-polyfill/src/router/lifecycle/lifecycle_annotations"; 265 | export * from "angular2-polyfill/src/router/interfaces"; 266 | export { ROUTER_PROVIDERS } from "angular2-polyfill/src/router/providers"; 267 | } 268 | declare module "angular2-polyfill/platform/browser" { 269 | export function bootstrap(base: any): void; 270 | } 271 | declare module "angular2-polyfill/src/platform/bootstrap/core" { 272 | export function bootstrap(ngModule: any): void; 273 | } 274 | declare module "angular2-polyfill/src/common/pipes/async.pipe" { 275 | /** 276 | * Thanks to @cvuorinen for the angular1-async-filter 277 | * https://github.com/cvuorinen/angular1-async-filter 278 | */ 279 | import { PipeTransform } from "angular2-polyfill/src/core/core"; 280 | export class AsyncPipe implements PipeTransform { 281 | private static currentObjectID; 282 | private static values; 283 | private static subscriptions; 284 | constructor(); 285 | static objectId(obj: any): any; 286 | transform(input: any, [scope]: [any]): any; 287 | } 288 | } 289 | declare module "angular2-polyfill/src/platform/utils/host" { 290 | export function parse(hostBindings: { 291 | string: string; 292 | }[]): { 293 | attrs: {}; 294 | events: {}; 295 | props: { 296 | raw: {}; 297 | expressions: {}; 298 | }; 299 | }; 300 | export function bind(scope: any, el: angular.IRootElementService, hostBindings: any, controllerAs?: string): void; 301 | } 302 | declare module "angular2-polyfill/src/platform/utils/injector" { 303 | export function inject(ngModule: ng.IModule, target: any): void; 304 | } 305 | declare module "angular2-polyfill/src/platform/utils/input" { 306 | /** 307 | * Bind the inputs defined on the target to the directive. 308 | */ 309 | export function bind(target: any, directive: any): void; 310 | } 311 | declare module "angular2-polyfill/src/platform/utils/output" { 312 | export function bind(scope: any, target: any, directive: any): void; 313 | } 314 | declare module "angular2-polyfill/src/platform/bootstrap/component" { 315 | export function bootstrap(ngModule: any, target: any, parentState?: any): string; 316 | } 317 | declare module "angular2-polyfill/src/platform/bootstrap/directive" { 318 | export function bootstrap(ngModule: any, target: any): void; 319 | } 320 | declare module "angular2-polyfill/src/platform/bootstrap/multi" { 321 | export function bootstrapMultiFactory(ngModule: any, name: any, target: any): void; 322 | export function bootstrapMultiInjectable(ngModule: any, name: any, target: any): void; 323 | export function bootstrapMultiValue(ngModule: any, name: any, target: any): void; 324 | } 325 | declare module "angular2-polyfill/src/platform/bootstrap/factory" { 326 | export function bootstrap(ngModule: any, target: any): any; 327 | } 328 | declare module "angular2-polyfill/src/platform/bootstrap/pipe" { 329 | export function bootstrap(ngModule: any, target: any): any; 330 | } 331 | declare module "angular2-polyfill/src/platform/bootstrap/value" { 332 | export function bootstrap(ngModule: any, target: any): any; 333 | } 334 | declare module "angular2-polyfill/src/platform/bootstrap/injectable" { 335 | export function bootstrap(ngModule: any, target: any): any; 336 | } 337 | declare module "angular2-polyfill/src/platform/bootstrap/provider" { 338 | import { Provider } from "angular2-polyfill/src/core/core"; 339 | export function bootstrap(ngModule: any, provider: Provider): void; 340 | } 341 | declare module "angular2-polyfill/src/platform/bootstrap/index" { 342 | export function bootstrap(ngModule: any, target: any): any; 343 | } 344 | declare module "angular2-polyfill/src/common/common" { 345 | export function bootstrap(ngModule: any): void; 346 | } 347 | declare module "angular2-polyfill/src/platform/upgrade" { 348 | export function bootstrap(ngModule: any, component: any, providers?: any[]): void; 349 | } 350 | declare module "angular2-polyfill/platform/upgrade" { 351 | export { bootstrap } from "angular2-polyfill/src/platform/upgrade"; 352 | } 353 | -------------------------------------------------------------------------------- /angular2-polyfill/bundles/angular2-polyfill.js: -------------------------------------------------------------------------------- 1 | System.registerDynamic("angular2-polyfill/src/http/http.service", ["rxjs", "../../core"], true, function($__require, exports, module) { 2 | "use strict"; 3 | ; 4 | var define, 5 | global = this, 6 | GLOBAL = this; 7 | var __decorate = (this && this.__decorate) || function(decorators, target, key, desc) { 8 | var c = arguments.length, 9 | r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, 10 | d; 11 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") 12 | r = Reflect.decorate(decorators, target, key, desc); 13 | else 14 | for (var i = decorators.length - 1; i >= 0; i--) 15 | if (d = decorators[i]) 16 | r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 17 | return c > 3 && r && Object.defineProperty(target, key, r), r; 18 | }; 19 | var __param = (this && this.__param) || function(paramIndex, decorator) { 20 | return function(target, key) { 21 | decorator(target, key, paramIndex); 22 | }; 23 | }; 24 | var rxjs_1 = $__require('rxjs'); 25 | var core_1 = $__require('../../core'); 26 | var Http = (function() { 27 | function Http(http) { 28 | this.http = http; 29 | } 30 | Http.prototype.get = function(url, options) { 31 | return rxjs_1.Observable.fromPromise(this.http.get(url, options)); 32 | }; 33 | Http.prototype.post = function(url, body, options) { 34 | return rxjs_1.Observable.fromPromise(this.http.post(url, body, options)); 35 | }; 36 | Http.prototype.put = function(url, body, options) { 37 | return rxjs_1.Observable.fromPromise(this.http.put(url, body, options)); 38 | }; 39 | Http.prototype.delete = function(url, options) { 40 | return rxjs_1.Observable.fromPromise(this.http.delete(url, options)); 41 | }; 42 | Http.prototype.patch = function(url, body, options) { 43 | return rxjs_1.Observable.fromPromise(this.http.patch(url, body, options)); 44 | }; 45 | Http.prototype.head = function(url, options) { 46 | return rxjs_1.Observable.fromPromise(this.http.head(url, options)); 47 | }; 48 | Http = __decorate([__param(0, core_1.Inject('$http'))], Http); 49 | return Http; 50 | }()); 51 | exports.Http = Http; 52 | return module.exports; 53 | }); 54 | 55 | System.registerDynamic("angular2-polyfill/src/http/providers", ["./http.service"], true, function($__require, exports, module) { 56 | "use strict"; 57 | ; 58 | var define, 59 | global = this, 60 | GLOBAL = this; 61 | var http_service_1 = $__require('./http.service'); 62 | exports.HTTP_PROVIDERS = [http_service_1.Http]; 63 | return module.exports; 64 | }); 65 | 66 | System.registerDynamic("angular2-polyfill/http", ["./src/http/http.service", "./src/http/providers"], true, function($__require, exports, module) { 67 | "use strict"; 68 | ; 69 | var define, 70 | global = this, 71 | GLOBAL = this; 72 | var http_service_1 = $__require('./src/http/http.service'); 73 | exports.Http = http_service_1.Http; 74 | var providers_1 = $__require('./src/http/providers'); 75 | exports.HTTP_PROVIDERS = providers_1.HTTP_PROVIDERS; 76 | return module.exports; 77 | }); 78 | 79 | System.registerDynamic("angular2-polyfill/src/platform/bootstrap/core", [], true, function($__require, exports, module) { 80 | "use strict"; 81 | ; 82 | var define, 83 | global = this, 84 | GLOBAL = this; 85 | var bootstrapped = false; 86 | function bootstrap(ngModule) { 87 | if (bootstrapped) { 88 | return; 89 | } 90 | bootstrapped = true; 91 | ngModule.run(['$q', '$window', function($q, $window) { 92 | $window.Promise = function(executor) { 93 | return $q(executor); 94 | }; 95 | $window.Promise.all = $q.all.bind($q); 96 | $window.Promise.reject = $q.reject.bind($q); 97 | $window.Promise.resolve = $q.when.bind($q); 98 | $window.Promise.race = function(promises) { 99 | var promiseMgr = $q.defer(); 100 | var resolve = function(result) { 101 | if (promiseMgr) { 102 | promiseMgr.resolve(result); 103 | promiseMgr = null; 104 | } 105 | }; 106 | var reject = function(err) { 107 | if (promiseMgr) { 108 | promiseMgr.reject(err); 109 | promiseMgr = null; 110 | } 111 | }; 112 | for (var i = 0; i < promises.length; i++) { 113 | promises[i].then(resolve).catch(reject); 114 | } 115 | return promiseMgr.promise; 116 | }; 117 | }]); 118 | angular.element(document).ready(function() { 119 | angular.bootstrap(document, [ngModule.name]); 120 | }); 121 | } 122 | exports.bootstrap = bootstrap; 123 | return module.exports; 124 | }); 125 | 126 | System.registerDynamic("angular2-polyfill/src/common/pipes/async.pipe", ["../../core/core"], true, function($__require, exports, module) { 127 | "use strict"; 128 | ; 129 | var define, 130 | global = this, 131 | GLOBAL = this; 132 | var __decorate = (this && this.__decorate) || function(decorators, target, key, desc) { 133 | var c = arguments.length, 134 | r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, 135 | d; 136 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") 137 | r = Reflect.decorate(decorators, target, key, desc); 138 | else 139 | for (var i = decorators.length - 1; i >= 0; i--) 140 | if (d = decorators[i]) 141 | r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 142 | return c > 3 && r && Object.defineProperty(target, key, r), r; 143 | }; 144 | var core_1 = $__require('../../core/core'); 145 | var AsyncPipe = (function() { 146 | function AsyncPipe() {} 147 | AsyncPipe.objectId = function(obj) { 148 | if (!obj.hasOwnProperty('__asyncFilterObjectID__')) { 149 | obj.__asyncFilterObjectID__ = ++AsyncPipe.currentObjectID; 150 | } 151 | return obj.__asyncFilterObjectID__; 152 | }; 153 | AsyncPipe.prototype.transform = function(input, _a) { 154 | var scope = _a[0]; 155 | if (!input || !(input.subscribe || input.then)) { 156 | return input; 157 | } 158 | var inputId = AsyncPipe.objectId(input); 159 | if (!(inputId in AsyncPipe.subscriptions)) { 160 | var subscriptionStrategy = input.subscribe && input.subscribe.bind(input) || input.success && input.success.bind(input) || input.then.bind(input); 161 | AsyncPipe.subscriptions[inputId] = subscriptionStrategy(function(value) { 162 | AsyncPipe.values[inputId] = value; 163 | if (scope && scope.$applyAsync) { 164 | scope.$applyAsync(); 165 | } 166 | }); 167 | } 168 | return AsyncPipe.values[inputId] || undefined; 169 | }; 170 | AsyncPipe.currentObjectID = 0; 171 | AsyncPipe.values = {}; 172 | AsyncPipe.subscriptions = {}; 173 | AsyncPipe = __decorate([core_1.Pipe({ 174 | name: 'async', 175 | pure: false 176 | })], AsyncPipe); 177 | return AsyncPipe; 178 | }()); 179 | exports.AsyncPipe = AsyncPipe; 180 | return module.exports; 181 | }); 182 | 183 | System.registerDynamic("angular2-polyfill/src/common/common", ["./pipes/async.pipe", "../platform/bootstrap/index"], true, function($__require, exports, module) { 184 | "use strict"; 185 | ; 186 | var define, 187 | global = this, 188 | GLOBAL = this; 189 | var async_pipe_1 = $__require('./pipes/async.pipe'); 190 | var utils = $__require('../platform/bootstrap/index'); 191 | function bootstrap(ngModule) { 192 | utils.bootstrap(ngModule, [async_pipe_1.AsyncPipe]); 193 | } 194 | exports.bootstrap = bootstrap; 195 | return module.exports; 196 | }); 197 | 198 | System.registerDynamic("angular2-polyfill/node_modules/decamelize/index", [], true, function($__require, exports, module) { 199 | "use strict"; 200 | ; 201 | var define, 202 | global = this, 203 | GLOBAL = this; 204 | module.exports = function(str, sep) { 205 | if (typeof str !== 'string') { 206 | throw new TypeError('Expected a string'); 207 | } 208 | sep = typeof sep === 'undefined' ? '_' : sep; 209 | return str.replace(/([a-z\d])([A-Z])/g, '$1' + sep + '$2').replace(/([A-Z]+)([A-Z][a-z\d]+)/g, '$1' + sep + '$2').toLowerCase(); 210 | }; 211 | return module.exports; 212 | }); 213 | 214 | System.registerDynamic("angular2-polyfill/src/platform/bootstrap/component", ["camelcase", "decamelize", "./index", "../utils/host", "../utils/injector", "../utils/input", "../utils/output"], true, function($__require, exports, module) { 215 | "use strict"; 216 | ; 217 | var define, 218 | global = this, 219 | GLOBAL = this; 220 | var camelcase = $__require('camelcase'); 221 | var decamelize = $__require('decamelize'); 222 | var utils = $__require('./index'); 223 | var host = $__require('../utils/host'); 224 | var injector = $__require('../utils/injector'); 225 | var input = $__require('../utils/input'); 226 | var output = $__require('../utils/output'); 227 | var map = {}; 228 | var states = {}; 229 | function bootstrap(ngModule, target, parentState) { 230 | var annotations = target.__annotations__; 231 | var component = annotations.component; 232 | var name = camelcase(component.selector || target.name); 233 | var styleElements = []; 234 | var headEl = angular.element(document).find('head'); 235 | if (map[target.name]) { 236 | return name; 237 | } 238 | map[target.name] = decamelize(component.selector || target.name, '-'); 239 | (component.providers || []).forEach(function(provider) { 240 | return utils.bootstrap(ngModule, provider); 241 | }); 242 | (component.directives || []).forEach(function(directive) { 243 | return utils.bootstrap(ngModule, directive); 244 | }); 245 | (component.pipes || []).forEach(function(pipe) { 246 | return utils.bootstrap(ngModule, pipe); 247 | }); 248 | (component.styles || []).forEach(function(style) { 249 | styleElements.push(angular.element('')); 250 | }); 251 | (component.styleUrls || []).forEach(function(url) { 252 | styleElements.push(angular.element('')); 253 | }); 254 | injector.inject(ngModule, target); 255 | var hostBindings = host.parse(component.host || {}); 256 | ngModule.controller(target.name, target).directive(name, ['$rootScope', '$compile', function($rootScope, $compile) { 257 | var directive = { 258 | restrict: 'E', 259 | scope: {}, 260 | bindToController: {}, 261 | controller: target.name, 262 | controllerAs: component.exportAs || '$ctrl', 263 | transclude: true, 264 | compile: function() { 265 | return {pre: function(scope, el) { 266 | styleElements.forEach(function(el) { 267 | return headEl.prepend(el); 268 | }); 269 | host.bind(scope, el, hostBindings, component.controllerAs); 270 | if (target.prototype.ngOnInit) { 271 | var init = $compile("
")(scope); 272 | el.append(init); 273 | } 274 | scope.$on('$destroy', function() { 275 | styleElements.forEach(function(el) { 276 | return el.remove(); 277 | }); 278 | if (target.prototype.ngOnDestroy) { 279 | scope[directive.controllerAs].ngOnDestroy(); 280 | } 281 | }); 282 | }}; 283 | } 284 | }; 285 | input.bind(target, directive); 286 | output.bind($rootScope, target, directive); 287 | if (component.template) { 288 | directive.template = component.template; 289 | } else { 290 | directive.templateUrl = component.templateUrl; 291 | } 292 | return directive; 293 | }]); 294 | if (annotations.routes) { 295 | var cmpStates_1 = []; 296 | annotations.routes.forEach(function(route) { 297 | var name = route.name || route.as; 298 | var routerAnnotations = route.component.__annotations__ && route.component.__annotations__.router; 299 | var state = { 300 | name: name, 301 | url: route.path, 302 | isDefault: route.useAsDefault === true 303 | }; 304 | if (route.component.name !== target.name) { 305 | bootstrap(ngModule, route.component, state); 306 | } 307 | if (state.url.substr(-4) === '/...') { 308 | state.url = state.url.substr(0, state.url.length - 4); 309 | state.abstract = true; 310 | } 311 | if (parentState && parentState.url && parentState.url.substr(-4) === '/...') { 312 | state.parent = parentState.name; 313 | } 314 | state.template = "<" + map[route.component.name] + ">"; 315 | cmpStates_1.push(state.name); 316 | states[name] = state; 317 | if (routerAnnotations && routerAnnotations.canActivate) { 318 | var hook = ['Router', '$state', '$stateParams']; 319 | if (Object.keys(routerAnnotations.canActivate.prototype).length > 0) { 320 | if (!routerAnnotations.canActivate.prototype.routerCanActivate) { 321 | throw new Error('@CanActivate class does not implement the `CanActivate` interface.'); 322 | } 323 | hook.push(utils.bootstrap(ngModule, routerAnnotations.canActivate)); 324 | } 325 | hook.push(function(router, $state, $stateParams, handler) { 326 | var fn = handler ? handler.routerCanActivate : routerAnnotations.canActivate; 327 | return Promise.all([router.generate([name, $stateParams]), $state.current.name.length === 0 ? null : router.generate([$state.current.name, $state.params])]).then(function(instructions) { 328 | return Promise.resolve(fn.apply(handler, instructions)); 329 | }).then(function(result) { 330 | if (!result) { 331 | return Promise.reject('could not activate'); 332 | } 333 | }); 334 | }); 335 | states[name].resolve = {routerCanActivate: hook}; 336 | } 337 | }); 338 | ngModule.config(['$urlRouterProvider', '$stateProvider', function($urlRouterProvider, $stateProvider) { 339 | cmpStates_1.forEach(function(name) { 340 | var state = states[name]; 341 | $stateProvider.state(name, state); 342 | if (state.isDefault) { 343 | if (state.parent) { 344 | var parentState_1 = states[state.parent]; 345 | var from = parentState_1.url; 346 | while (parentState_1.parent) { 347 | parentState_1 = states[parentState_1.parent]; 348 | from = parentState_1.url + from; 349 | } 350 | $urlRouterProvider.when(from, from + state.url); 351 | } else { 352 | $urlRouterProvider.otherwise(state.url); 353 | } 354 | } 355 | }); 356 | }]); 357 | } 358 | return name; 359 | } 360 | exports.bootstrap = bootstrap; 361 | return module.exports; 362 | }); 363 | 364 | System.registerDynamic("angular2-polyfill/src/platform/utils/host", ["camelcase", "dot-prop"], true, function($__require, exports, module) { 365 | "use strict"; 366 | ; 367 | var define, 368 | global = this, 369 | GLOBAL = this; 370 | var camelcase = $__require('camelcase'); 371 | var dotProp = $__require('dot-prop'); 372 | function parseHostBinding(key) { 373 | var regex = [{ 374 | type: 'attr', 375 | regex: /^([a-zA-Z]+)$/ 376 | }, { 377 | type: 'prop', 378 | regex: /^\[([a-zA-Z\.-]+)\]$/ 379 | }, { 380 | type: 'event', 381 | regex: /^\(([a-zA-Z]+)\)$/ 382 | }]; 383 | for (var i = 0; i < regex.length; i++) { 384 | var match = key.match(regex[i].regex); 385 | if (match !== null) { 386 | return { 387 | type: regex[i].type, 388 | value: match[1] 389 | }; 390 | } 391 | } 392 | ; 393 | return { 394 | type: undefined, 395 | value: key 396 | }; 397 | } 398 | function applyValueToProperties(el, properties, value) { 399 | properties.forEach(function(property) { 400 | var splitted = property.split('.'); 401 | if (splitted.length === 1) { 402 | el.prop(camelcase(property), value); 403 | } else { 404 | var root = splitted.shift(); 405 | if (root === 'class') { 406 | var method = value ? 'addClass' : 'removeClass'; 407 | el[method](splitted.join('.')); 408 | } else { 409 | var runner = el.prop(camelcase(root)); 410 | while (splitted.length > 1) { 411 | runner = runner[camelcase(splitted.shift())]; 412 | } 413 | runner[camelcase(splitted.shift())] = value; 414 | } 415 | } 416 | }); 417 | } 418 | function parse(hostBindings) { 419 | var result = { 420 | attrs: {}, 421 | events: {}, 422 | props: { 423 | raw: {}, 424 | expressions: {} 425 | } 426 | }; 427 | Object.keys(hostBindings).forEach(function(key) { 428 | var value = hostBindings[key]; 429 | var parsed = parseHostBinding(key); 430 | if (parsed.type === 'attr') { 431 | result.attrs[parsed.value] = value; 432 | } else if (parsed.type === 'event') { 433 | var handler = value.match(/^([a-zA-Z]+)\((.*?)\)$/); 434 | var method = handler[1]; 435 | var params = handler[2].length === 0 ? [] : handler[2].split(/,[ ]*/); 436 | result.events[parsed.value] = { 437 | method: method, 438 | params: params 439 | }; 440 | } else if (parsed.type === 'prop') { 441 | var raw = value.match(/^['"](.*?)['"]$/); 442 | var map = 'expressions'; 443 | if (raw) { 444 | value = raw[1]; 445 | map = 'raw'; 446 | } 447 | result.props[map][value] = result.props[map][value] || []; 448 | result.props[map][value].push(parsed.value); 449 | } 450 | }); 451 | return result; 452 | } 453 | exports.parse = parse; 454 | function bind(scope, el, hostBindings, controllerAs) { 455 | if (controllerAs === void 0) { 456 | controllerAs = '$ctrl'; 457 | } 458 | Object.keys(hostBindings.attrs).forEach(function(attribute) { 459 | el.attr(attribute, hostBindings.attrs[attribute]); 460 | }); 461 | Object.keys(hostBindings.events).forEach(function(event) { 462 | var target = hostBindings.events[event]; 463 | el.bind(event, function(e) { 464 | var ctx = {$event: e}; 465 | scope.$apply(function() { 466 | scope[controllerAs][target.method].apply(scope[controllerAs], target.params.map(function(param) { 467 | return dotProp.get(ctx, param); 468 | })); 469 | }); 470 | }); 471 | }); 472 | Object.keys(hostBindings.props.raw).forEach(function(value) { 473 | var properties = hostBindings.props.raw[value]; 474 | applyValueToProperties(el, properties, value); 475 | }); 476 | Object.keys(hostBindings.props.expressions).forEach(function(expression) { 477 | var properties = hostBindings.props.expressions[expression]; 478 | scope.$watch(controllerAs + "." + expression, function(newValue) { 479 | applyValueToProperties(el, properties, newValue); 480 | }); 481 | }); 482 | } 483 | exports.bind = bind; 484 | return module.exports; 485 | }); 486 | 487 | System.registerDynamic("angular2-polyfill/src/platform/utils/input", [], true, function($__require, exports, module) { 488 | "use strict"; 489 | ; 490 | var define, 491 | global = this, 492 | GLOBAL = this; 493 | function bind(target, directive) { 494 | var annotations = target.__annotations__; 495 | var component = annotations.component || annotations.directive; 496 | function toBinding(key, value) { 497 | var match = value.match(/^([@=<])?(.*)?$/); 498 | if (match[1]) { 499 | return { 500 | key: match[2] || key, 501 | value: match[1] + (match[2] || key) 502 | }; 503 | } 504 | var sign = '@'; 505 | if (Reflect.hasMetadata('design:type', target.prototype, key)) { 506 | var type = Reflect.getMetadata('design:type', target.prototype, key); 507 | if (type.name !== 'String' && type.name !== 'Number' && type.name !== 'Boolean') { 508 | sign = '='; 509 | } 510 | } 511 | return { 512 | key: key, 513 | value: sign + value 514 | }; 515 | } 516 | (component.inputs || []).forEach(function(key) { 517 | var mapping = key.split(/:[ ]*/); 518 | var binding = toBinding(mapping[0], mapping[1] || mapping[0]); 519 | directive.bindToController[binding.key] = binding.value; 520 | }); 521 | Object.keys(annotations.inputs || {}).forEach(function(key) { 522 | var binding = toBinding(key, annotations.inputs[key]); 523 | directive.bindToController[binding.key] = binding.value; 524 | }); 525 | } 526 | exports.bind = bind; 527 | return module.exports; 528 | }); 529 | 530 | System.registerDynamic("angular2-polyfill/src/platform/utils/output", [], true, function($__require, exports, module) { 531 | "use strict"; 532 | ; 533 | var define, 534 | global = this, 535 | GLOBAL = this; 536 | function attachPropertyHook(scope, target, key, name) { 537 | var wrapper = "__" + name + "Fn"; 538 | Object.defineProperty(target.prototype, key, { 539 | enumerable: true, 540 | configurable: true, 541 | get: function() { 542 | return this[("_" + name)]; 543 | }, 544 | set: function(value) { 545 | var _this = this; 546 | if (this[wrapper] === undefined) { 547 | this[wrapper] = value; 548 | } 549 | if (typeof value === 'function') { 550 | this[("_" + name)] = this[wrapper]; 551 | } else if (value && value.emit && value.subscribe) { 552 | this[("_" + name)] = value; 553 | value.subscribe(function(e) { 554 | scope.$apply(function() { 555 | _this[wrapper]({$event: e}); 556 | }); 557 | }); 558 | } 559 | } 560 | }); 561 | } 562 | function bind(scope, target, directive) { 563 | var annotations = target.__annotations__; 564 | var component = annotations.component || annotations.directive; 565 | (component.outputs || []).forEach(function(key) { 566 | var mapping = key.split(/:[ ]*/); 567 | var name = mapping[1] || mapping[0]; 568 | attachPropertyHook(scope, target, key, name); 569 | directive.bindToController[mapping[0]] = "&" + name; 570 | }); 571 | Object.keys(annotations.outputs || {}).forEach(function(key) { 572 | var name = annotations.outputs[key]; 573 | attachPropertyHook(scope, target, key, name); 574 | directive.bindToController[key] = "&" + name; 575 | }); 576 | } 577 | exports.bind = bind; 578 | return module.exports; 579 | }); 580 | 581 | System.registerDynamic("angular2-polyfill/src/platform/bootstrap/directive", ["../utils/host", "../utils/injector", "../utils/input", "../utils/output"], true, function($__require, exports, module) { 582 | "use strict"; 583 | ; 584 | var define, 585 | global = this, 586 | GLOBAL = this; 587 | var host = $__require('../utils/host'); 588 | var injector = $__require('../utils/injector'); 589 | var input = $__require('../utils/input'); 590 | var output = $__require('../utils/output'); 591 | function parseSelector(selector) { 592 | var regex = [{ 593 | key: 'A', 594 | value: /^\[([a-zA-Z]+)\]$/ 595 | }, { 596 | key: 'C', 597 | value: /^\.([a-zA-Z]+)$/ 598 | }]; 599 | for (var i = 0; i < regex.length; i++) { 600 | var result = selector.match(regex[i].value); 601 | if (result !== null) { 602 | return { 603 | restrict: regex[i].key, 604 | name: result[1] 605 | }; 606 | } 607 | } 608 | ; 609 | throw new Error("Selector " + selector + " could not be parsed"); 610 | } 611 | function bootstrap(ngModule, target) { 612 | var annotations = target.__annotations__; 613 | var directive = annotations.directive; 614 | var selector = parseSelector(directive.selector); 615 | var hostBindings = host.parse(directive.host || {}); 616 | injector.inject(ngModule, target); 617 | ngModule.controller(target.name, target).directive(selector.name, ['$rootScope', function($rootScope) { 618 | var declaration = { 619 | restrict: selector.restrict, 620 | scope: {}, 621 | bindToController: {}, 622 | controller: target.name, 623 | controllerAs: '$ctrl', 624 | link: function(scope, el) { 625 | return host.bind(scope, el, hostBindings); 626 | } 627 | }; 628 | input.bind(target, declaration); 629 | output.bind($rootScope, target, declaration); 630 | return declaration; 631 | }]); 632 | } 633 | exports.bootstrap = bootstrap; 634 | return module.exports; 635 | }); 636 | 637 | System.registerDynamic("angular2-polyfill/src/platform/bootstrap/factory", ["../utils/injector", "./multi"], true, function($__require, exports, module) { 638 | "use strict"; 639 | ; 640 | var define, 641 | global = this, 642 | GLOBAL = this; 643 | var injector = $__require('../utils/injector'); 644 | var multi_1 = $__require('./multi'); 645 | function bootstrap(ngModule, target) { 646 | var annotations = target.__annotations__; 647 | var factory = annotations.factory; 648 | injector.inject(ngModule, target); 649 | var name = factory.name || target.name; 650 | if (annotations.multi === true) { 651 | multi_1.bootstrapMultiFactory(ngModule, name, target); 652 | } else { 653 | ngModule.factory(name, target); 654 | } 655 | return name; 656 | } 657 | exports.bootstrap = bootstrap; 658 | return module.exports; 659 | }); 660 | 661 | System.registerDynamic("angular2-polyfill/src/platform/bootstrap/pipe", ["../utils/injector"], true, function($__require, exports, module) { 662 | "use strict"; 663 | ; 664 | var define, 665 | global = this, 666 | GLOBAL = this; 667 | var injector = $__require('../utils/injector'); 668 | function bootstrap(ngModule, target) { 669 | var pipe = target.__annotations__.pipe; 670 | injector.inject(ngModule, target); 671 | var filter = target.$inject || []; 672 | filter.push(function() { 673 | var args = []; 674 | for (var _i = 0; _i < arguments.length; _i++) { 675 | args[_i - 0] = arguments[_i]; 676 | } 677 | var instance = new (target.bind.apply(target, [void 0].concat(args)))(); 678 | var filter = function(value) { 679 | var args = []; 680 | for (var _i = 1; _i < arguments.length; _i++) { 681 | args[_i - 1] = arguments[_i]; 682 | } 683 | return instance.transform(value, args); 684 | }; 685 | filter.$stateful = pipe.pure === false; 686 | return filter; 687 | }); 688 | ngModule.filter(pipe.name, filter); 689 | return pipe.name; 690 | } 691 | exports.bootstrap = bootstrap; 692 | return module.exports; 693 | }); 694 | 695 | System.registerDynamic("angular2-polyfill/src/platform/bootstrap/value", ["./multi"], true, function($__require, exports, module) { 696 | "use strict"; 697 | ; 698 | var define, 699 | global = this, 700 | GLOBAL = this; 701 | var multi_1 = $__require('./multi'); 702 | function bootstrap(ngModule, target) { 703 | var annotations = target.__annotations__; 704 | var value = annotations.value; 705 | var name = value.name; 706 | var ret = value.value; 707 | if (annotations.multi === true) { 708 | multi_1.bootstrapMultiValue(ngModule, name, ret); 709 | } else { 710 | ngModule.value(name, ret); 711 | } 712 | return name; 713 | } 714 | exports.bootstrap = bootstrap; 715 | return module.exports; 716 | }); 717 | 718 | System.registerDynamic("angular2-polyfill/src/platform/utils/injector", [], true, function($__require, exports, module) { 719 | "use strict"; 720 | ; 721 | var define, 722 | global = this, 723 | GLOBAL = this; 724 | function createOptionalInject(ngModule, injectable) { 725 | var name = "@Optional(" + injectable + ")"; 726 | var factory = function($injector) { 727 | if ($injector.has(injectable)) { 728 | return $injector.get(injectable); 729 | } 730 | return null; 731 | }; 732 | factory.$inject = ['$injector']; 733 | ngModule.factory(name, factory); 734 | return name; 735 | } 736 | function inject(ngModule, target) { 737 | var annotations = target.__annotations__ || {}; 738 | var injectables = []; 739 | if (annotations.inject) { 740 | annotations.inject.forEach(function(injectable, index) { 741 | var name = typeof injectable === 'string' ? injectable : injectable.name; 742 | if (annotations.optional && annotations.optional[index] === true) { 743 | name = createOptionalInject(ngModule, name); 744 | } 745 | injectables[index] = name; 746 | }); 747 | } 748 | if (Reflect.hasMetadata('design:paramtypes', target)) { 749 | Reflect.getMetadata('design:paramtypes', target).forEach(function(type, index) { 750 | if (type.name !== 'Object' && injectables[index] === undefined) { 751 | var name_1 = type.name; 752 | if (annotations.optional && annotations.optional[index] === true) { 753 | name_1 = createOptionalInject(ngModule, name_1); 754 | } 755 | injectables[index] = name_1; 756 | } 757 | }); 758 | } 759 | target.$inject = injectables; 760 | } 761 | exports.inject = inject; 762 | return module.exports; 763 | }); 764 | 765 | System.registerDynamic("angular2-polyfill/src/platform/bootstrap/multi", [], true, function($__require, exports, module) { 766 | "use strict"; 767 | ; 768 | var define, 769 | global = this, 770 | GLOBAL = this; 771 | var id = 0; 772 | var prefix = 'ng2Multi'; 773 | var map = {}; 774 | function bootstrapMulti(fn, ngModule, name, target) { 775 | map[name] = map[name] || []; 776 | var privateName = prefix + "_" + fn + "_" + name + "_" + ++id; 777 | ngModule[fn](privateName, target); 778 | map[name].push(privateName); 779 | ngModule.factory(name, map[name].concat([function() { 780 | var args = []; 781 | for (var _i = 0; _i < arguments.length; _i++) { 782 | args[_i - 0] = arguments[_i]; 783 | } 784 | return args; 785 | }])); 786 | } 787 | function bootstrapMultiFactory(ngModule, name, target) { 788 | bootstrapMulti('factory', ngModule, name, target); 789 | } 790 | exports.bootstrapMultiFactory = bootstrapMultiFactory; 791 | function bootstrapMultiInjectable(ngModule, name, target) { 792 | bootstrapMulti('service', ngModule, name, target); 793 | } 794 | exports.bootstrapMultiInjectable = bootstrapMultiInjectable; 795 | function bootstrapMultiValue(ngModule, name, target) { 796 | bootstrapMulti('value', ngModule, name, target); 797 | } 798 | exports.bootstrapMultiValue = bootstrapMultiValue; 799 | return module.exports; 800 | }); 801 | 802 | System.registerDynamic("angular2-polyfill/src/platform/bootstrap/injectable", ["../utils/injector", "./multi"], true, function($__require, exports, module) { 803 | "use strict"; 804 | ; 805 | var define, 806 | global = this, 807 | GLOBAL = this; 808 | var injector = $__require('../utils/injector'); 809 | var multi_1 = $__require('./multi'); 810 | function bootstrap(ngModule, target) { 811 | var annotations = target.__annotations__ || {}; 812 | var injectable = annotations.injectable || {}; 813 | injector.inject(ngModule, target); 814 | var name = injectable.name || target.name; 815 | if (annotations.multi === true) { 816 | multi_1.bootstrapMultiInjectable(ngModule, name, target); 817 | } else { 818 | ngModule.service(name, target); 819 | } 820 | return name; 821 | } 822 | exports.bootstrap = bootstrap; 823 | return module.exports; 824 | }); 825 | 826 | System.registerDynamic("angular2-polyfill/src/platform/bootstrap/provider", ["../../utils", "./index"], true, function($__require, exports, module) { 827 | "use strict"; 828 | ; 829 | var define, 830 | global = this, 831 | GLOBAL = this; 832 | var utils_1 = $__require('../../utils'); 833 | var utils = $__require('./index'); 834 | function bootstrap(ngModule, provider) { 835 | var target = {}; 836 | var name = utils_1.toInjectorName(provider.token); 837 | var inject = (provider.deps || []).map(utils_1.toInjectorName); 838 | if (provider.useValue) { 839 | var value = provider.useValue; 840 | utils_1.annotate(target, 'value', { 841 | name: name, 842 | value: value 843 | }); 844 | } else if (provider.useFactory) { 845 | target = provider.useFactory; 846 | utils_1.annotate(target, 'factory', {name: name}); 847 | utils_1.annotate(target, 'inject', inject); 848 | } else if (provider.useClass) { 849 | target = provider.useClass; 850 | utils_1.annotate(target, 'injectable', {name: name}); 851 | } else if (provider.useExisting) { 852 | target = function(v) { 853 | return v; 854 | }; 855 | utils_1.annotate(target, 'factory', {name: name}); 856 | utils_1.annotate(target, 'inject', [utils_1.toInjectorName(provider.useExisting)]); 857 | } 858 | utils_1.annotate(target, 'multi', provider.multi); 859 | utils.bootstrap(ngModule, target); 860 | } 861 | exports.bootstrap = bootstrap; 862 | return module.exports; 863 | }); 864 | 865 | System.registerDynamic("angular2-polyfill/src/platform/bootstrap/index", ["../../core/core", "./component", "./directive", "./factory", "./pipe", "./value", "./injectable", "./provider"], true, function($__require, exports, module) { 866 | "use strict"; 867 | ; 868 | var define, 869 | global = this, 870 | GLOBAL = this; 871 | var core_1 = $__require('../../core/core'); 872 | var component_1 = $__require('./component'); 873 | var directive_1 = $__require('./directive'); 874 | var factory_1 = $__require('./factory'); 875 | var pipe_1 = $__require('./pipe'); 876 | var value_1 = $__require('./value'); 877 | var injectable_1 = $__require('./injectable'); 878 | var provider_1 = $__require('./provider'); 879 | function bootstrap(ngModule, target) { 880 | if (Array.isArray(target)) { 881 | return target.forEach(function(target) { 882 | return bootstrap(ngModule, target); 883 | }); 884 | } 885 | if (target.__annotations__) { 886 | if (target.__annotations__.component) { 887 | return component_1.bootstrap(ngModule, target); 888 | } else if (target.__annotations__.directive) { 889 | return directive_1.bootstrap(ngModule, target); 890 | } else if (target.__annotations__.factory) { 891 | return factory_1.bootstrap(ngModule, target); 892 | } else if (target.__annotations__.pipe) { 893 | return pipe_1.bootstrap(ngModule, target); 894 | } else if (target.__annotations__.value) { 895 | return value_1.bootstrap(ngModule, target); 896 | } 897 | } 898 | if (target instanceof core_1.Provider) { 899 | return provider_1.bootstrap(ngModule, target); 900 | } 901 | return injectable_1.bootstrap(ngModule, target); 902 | } 903 | exports.bootstrap = bootstrap; 904 | return module.exports; 905 | }); 906 | 907 | System.registerDynamic("angular2-polyfill/src/platform/upgrade", ["./bootstrap/core", "../common/common", "./bootstrap/index", "../core/core"], true, function($__require, exports, module) { 908 | "use strict"; 909 | ; 910 | var define, 911 | global = this, 912 | GLOBAL = this; 913 | var core_1 = $__require('./bootstrap/core'); 914 | var common_1 = $__require('../common/common'); 915 | var index_1 = $__require('./bootstrap/index'); 916 | var core_2 = $__require('../core/core'); 917 | function bootstrap(ngModule, component, providers) { 918 | if (providers === void 0) { 919 | providers = []; 920 | } 921 | core_1.bootstrap(ngModule); 922 | common_1.bootstrap(ngModule); 923 | index_1.bootstrap(ngModule, core_2.provide(core_2.Injector, {useFactory: function() { 924 | return new core_2.Injector(); 925 | }})); 926 | providers.forEach(function(provider) { 927 | return index_1.bootstrap(ngModule, provider); 928 | }); 929 | index_1.bootstrap(ngModule, component); 930 | } 931 | exports.bootstrap = bootstrap; 932 | return module.exports; 933 | }); 934 | 935 | System.registerDynamic("angular2-polyfill/platform/upgrade", ["../src/platform/upgrade"], true, function($__require, exports, module) { 936 | "use strict"; 937 | ; 938 | var define, 939 | global = this, 940 | GLOBAL = this; 941 | var upgrade_1 = $__require('../src/platform/upgrade'); 942 | exports.bootstrap = upgrade_1.bootstrap; 943 | return module.exports; 944 | }); 945 | 946 | System.registerDynamic("angular2-polyfill/src/router/decorators/RouteConfig", ["../../utils"], true, function($__require, exports, module) { 947 | "use strict"; 948 | ; 949 | var define, 950 | global = this, 951 | GLOBAL = this; 952 | var utils_1 = $__require('../../utils'); 953 | function RouteConfig(routes) { 954 | return function(target) { 955 | utils_1.annotate(target, 'routes', routes); 956 | }; 957 | } 958 | exports.RouteConfig = RouteConfig; 959 | return module.exports; 960 | }); 961 | 962 | System.registerDynamic("angular2-polyfill/src/router/lifecycle/lifecycle_annotations", ["../../utils"], true, function($__require, exports, module) { 963 | "use strict"; 964 | ; 965 | var define, 966 | global = this, 967 | GLOBAL = this; 968 | var utils_1 = $__require('../../utils'); 969 | function CanActivate(hook) { 970 | return function(target) { 971 | utils_1.annotate(target, 'router.canActivate', hook); 972 | }; 973 | } 974 | exports.CanActivate = CanActivate; 975 | return module.exports; 976 | }); 977 | 978 | System.registerDynamic("angular2-polyfill/src/router/router", ["../../core", "./instruction"], true, function($__require, exports, module) { 979 | "use strict"; 980 | ; 981 | var define, 982 | global = this, 983 | GLOBAL = this; 984 | var __decorate = (this && this.__decorate) || function(decorators, target, key, desc) { 985 | var c = arguments.length, 986 | r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, 987 | d; 988 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") 989 | r = Reflect.decorate(decorators, target, key, desc); 990 | else 991 | for (var i = decorators.length - 1; i >= 0; i--) 992 | if (d = decorators[i]) 993 | r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 994 | return c > 3 && r && Object.defineProperty(target, key, r), r; 995 | }; 996 | var __param = (this && this.__param) || function(paramIndex, decorator) { 997 | return function(target, key) { 998 | decorator(target, key, paramIndex); 999 | }; 1000 | }; 1001 | var core_1 = $__require('../../core'); 1002 | var instruction_1 = $__require('./instruction'); 1003 | var Router = (function() { 1004 | function Router(state) { 1005 | this.state = state; 1006 | } 1007 | Router.prototype.isRouteActive = function(instruction) { 1008 | return this.state.is(instruction._state, instruction.urlParams); 1009 | }; 1010 | Router.prototype.navigate = function(linkParams) { 1011 | return this.state.go(linkParams[0], linkParams[1] || {}); 1012 | }; 1013 | Router.prototype.renavigate = function() { 1014 | return this.state.reload(this.state.current); 1015 | }; 1016 | Router.prototype.generate = function(linkParams) { 1017 | var state = linkParams[0]; 1018 | var params = linkParams[1] || {}; 1019 | var url = this.state.href(state, params); 1020 | var instruction = new instruction_1.Instruction(); 1021 | instruction._state = state; 1022 | instruction.urlPath = this.state.href(state, params); 1023 | instruction.urlParams = params; 1024 | return Promise.resolve(instruction); 1025 | }; 1026 | Router = __decorate([__param(0, core_1.Inject('$state'))], Router); 1027 | return Router; 1028 | }()); 1029 | exports.Router = Router; 1030 | return module.exports; 1031 | }); 1032 | 1033 | System.registerDynamic("angular2-polyfill/src/core/decorators/Component", ["../../utils"], true, function($__require, exports, module) { 1034 | "use strict"; 1035 | ; 1036 | var define, 1037 | global = this, 1038 | GLOBAL = this; 1039 | var utils_1 = $__require('../../utils'); 1040 | function Component(component) { 1041 | return function(target) { 1042 | utils_1.annotate(target, 'component', component); 1043 | }; 1044 | } 1045 | exports.Component = Component; 1046 | return module.exports; 1047 | }); 1048 | 1049 | System.registerDynamic("angular2-polyfill/src/core/decorators/Directive", ["../../utils"], true, function($__require, exports, module) { 1050 | "use strict"; 1051 | ; 1052 | var define, 1053 | global = this, 1054 | GLOBAL = this; 1055 | var utils_1 = $__require('../../utils'); 1056 | function Directive(options) { 1057 | return function(target) { 1058 | utils_1.annotate(target, 'directive', options); 1059 | }; 1060 | } 1061 | exports.Directive = Directive; 1062 | return module.exports; 1063 | }); 1064 | 1065 | System.registerDynamic("angular2-polyfill/src/core/decorators/Inject", [], true, function($__require, exports, module) { 1066 | "use strict"; 1067 | ; 1068 | var define, 1069 | global = this, 1070 | GLOBAL = this; 1071 | function Inject(token) { 1072 | return function(target, propertyKey, parameterIndex) { 1073 | if (!target.__annotations__) { 1074 | target.__annotations__ = {}; 1075 | } 1076 | if (!target.__annotations__.inject) { 1077 | target.__annotations__.inject = []; 1078 | } 1079 | target.__annotations__.inject[parameterIndex] = token; 1080 | }; 1081 | } 1082 | exports.Inject = Inject; 1083 | return module.exports; 1084 | }); 1085 | 1086 | System.registerDynamic("angular2-polyfill/src/core/decorators/Injectable", ["../../utils"], true, function($__require, exports, module) { 1087 | "use strict"; 1088 | ; 1089 | var define, 1090 | global = this, 1091 | GLOBAL = this; 1092 | var utils_1 = $__require('../../utils'); 1093 | function Injectable() { 1094 | return function(target) { 1095 | utils_1.annotate(target, 'injectable', true); 1096 | }; 1097 | } 1098 | exports.Injectable = Injectable; 1099 | return module.exports; 1100 | }); 1101 | 1102 | System.registerDynamic("angular2-polyfill/src/core/decorators/Input", ["../../utils"], true, function($__require, exports, module) { 1103 | "use strict"; 1104 | ; 1105 | var define, 1106 | global = this, 1107 | GLOBAL = this; 1108 | var utils_1 = $__require('../../utils'); 1109 | function Input(bindingPropertyName) { 1110 | return function(target, propertyKey) { 1111 | utils_1.annotate(target.constructor, "inputs." + propertyKey, bindingPropertyName || propertyKey); 1112 | }; 1113 | } 1114 | exports.Input = Input; 1115 | return module.exports; 1116 | }); 1117 | 1118 | System.registerDynamic("angular2-polyfill/src/core/decorators/Output", ["../../utils"], true, function($__require, exports, module) { 1119 | "use strict"; 1120 | ; 1121 | var define, 1122 | global = this, 1123 | GLOBAL = this; 1124 | var utils_1 = $__require('../../utils'); 1125 | function Output(bindingPropertyName) { 1126 | return function(target, propertyKey) { 1127 | utils_1.annotate(target.constructor, "outputs." + propertyKey, bindingPropertyName || propertyKey); 1128 | }; 1129 | } 1130 | exports.Output = Output; 1131 | return module.exports; 1132 | }); 1133 | 1134 | System.registerDynamic("angular2-polyfill/src/core/decorators/Pipe", ["../../utils"], true, function($__require, exports, module) { 1135 | "use strict"; 1136 | ; 1137 | var define, 1138 | global = this, 1139 | GLOBAL = this; 1140 | var utils_1 = $__require('../../utils'); 1141 | function Pipe(pipe) { 1142 | return function(target) { 1143 | utils_1.annotate(target, 'pipe', pipe); 1144 | }; 1145 | } 1146 | exports.Pipe = Pipe; 1147 | return module.exports; 1148 | }); 1149 | 1150 | System.registerDynamic("angular2-polyfill/src/core/decorators/Optional", [], true, function($__require, exports, module) { 1151 | "use strict"; 1152 | ; 1153 | var define, 1154 | global = this, 1155 | GLOBAL = this; 1156 | function Optional() { 1157 | return function(target, propertyKey, parameterIndex) { 1158 | if (!target.__annotations__) { 1159 | target.__annotations__ = {}; 1160 | } 1161 | target.__annotations__.optional = {}; 1162 | target.__annotations__.optional[parameterIndex] = true; 1163 | }; 1164 | } 1165 | exports.Optional = Optional; 1166 | return module.exports; 1167 | }); 1168 | 1169 | System.registerDynamic("angular2-polyfill/src/core/functions/provide", ["../core"], true, function($__require, exports, module) { 1170 | "use strict"; 1171 | ; 1172 | var define, 1173 | global = this, 1174 | GLOBAL = this; 1175 | var core_1 = $__require('../core'); 1176 | function provide(token, options) { 1177 | return new core_1.Provider(token, options); 1178 | } 1179 | exports.provide = provide; 1180 | return module.exports; 1181 | }); 1182 | 1183 | System.registerDynamic("angular2-polyfill/src/core/classes/provider", [], true, function($__require, exports, module) { 1184 | "use strict"; 1185 | ; 1186 | var define, 1187 | global = this, 1188 | GLOBAL = this; 1189 | var Provider = (function() { 1190 | function Provider(token, options) { 1191 | this.token = token; 1192 | this.useClass = options.useClass; 1193 | this.useValue = options.useValue; 1194 | this.useExisting = options.useExisting; 1195 | this.useFactory = options.useFactory; 1196 | this.deps = options.deps; 1197 | this.multi = options.multi; 1198 | } 1199 | return Provider; 1200 | }()); 1201 | exports.Provider = Provider; 1202 | return module.exports; 1203 | }); 1204 | 1205 | System.registerDynamic("angular2-polyfill/node_modules/is-obj/index", [], true, function($__require, exports, module) { 1206 | "use strict"; 1207 | ; 1208 | var define, 1209 | global = this, 1210 | GLOBAL = this; 1211 | module.exports = function(x) { 1212 | var type = typeof x; 1213 | return x !== null && (type === 'object' || type === 'function'); 1214 | }; 1215 | return module.exports; 1216 | }); 1217 | 1218 | System.registerDynamic("angular2-polyfill/node_modules/dot-prop/index", ["is-obj"], true, function($__require, exports, module) { 1219 | "use strict"; 1220 | ; 1221 | var define, 1222 | global = this, 1223 | GLOBAL = this; 1224 | var isObj = $__require('is-obj'); 1225 | module.exports.get = function(obj, path) { 1226 | if (!isObj(obj) || typeof path !== 'string') { 1227 | return obj; 1228 | } 1229 | var pathArr = getPathSegments(path); 1230 | for (var i = 0; i < pathArr.length; i++) { 1231 | obj = obj[pathArr[i]]; 1232 | if (obj === undefined) { 1233 | break; 1234 | } 1235 | } 1236 | return obj; 1237 | }; 1238 | module.exports.set = function(obj, path, value) { 1239 | if (!isObj(obj) || typeof path !== 'string') { 1240 | return; 1241 | } 1242 | var pathArr = getPathSegments(path); 1243 | for (var i = 0; i < pathArr.length; i++) { 1244 | var p = pathArr[i]; 1245 | if (!isObj(obj[p])) { 1246 | obj[p] = {}; 1247 | } 1248 | if (i === pathArr.length - 1) { 1249 | obj[p] = value; 1250 | } 1251 | obj = obj[p]; 1252 | } 1253 | }; 1254 | module.exports.delete = function(obj, path) { 1255 | if (!isObj(obj) || typeof path !== 'string') { 1256 | return; 1257 | } 1258 | var pathArr = getPathSegments(path); 1259 | for (var i = 0; i < pathArr.length; i++) { 1260 | var p = pathArr[i]; 1261 | if (i === pathArr.length - 1) { 1262 | delete obj[p]; 1263 | return; 1264 | } 1265 | obj = obj[p]; 1266 | } 1267 | }; 1268 | module.exports.has = function(obj, path) { 1269 | if (!isObj(obj) || typeof path !== 'string') { 1270 | return false; 1271 | } 1272 | var pathArr = getPathSegments(path); 1273 | for (var i = 0; i < pathArr.length; i++) { 1274 | obj = obj[pathArr[i]]; 1275 | if (obj === undefined) { 1276 | return false; 1277 | } 1278 | } 1279 | return true; 1280 | }; 1281 | function getPathSegments(path) { 1282 | var pathArr = path.split('.'); 1283 | var parts = []; 1284 | for (var i = 0; i < pathArr.length; i++) { 1285 | var p = pathArr[i]; 1286 | while (p[p.length - 1] === '\\') { 1287 | p = p.slice(0, -1) + '.'; 1288 | p += pathArr[++i]; 1289 | } 1290 | parts.push(p); 1291 | } 1292 | return parts; 1293 | } 1294 | return module.exports; 1295 | }); 1296 | 1297 | System.registerDynamic("angular2-polyfill/node_modules/camelcase/index", [], true, function($__require, exports, module) { 1298 | "use strict"; 1299 | ; 1300 | var define, 1301 | global = this, 1302 | GLOBAL = this; 1303 | function preserveCamelCase(str) { 1304 | var isLastCharLower = false; 1305 | for (var i = 0; i < str.length; i++) { 1306 | var c = str.charAt(i); 1307 | if (isLastCharLower && (/[a-zA-Z]/).test(c) && c.toUpperCase() === c) { 1308 | str = str.substr(0, i) + '-' + str.substr(i); 1309 | isLastCharLower = false; 1310 | i++; 1311 | } else { 1312 | isLastCharLower = (c.toLowerCase() === c); 1313 | } 1314 | } 1315 | return str; 1316 | } 1317 | module.exports = function() { 1318 | var str = [].map.call(arguments, function(str) { 1319 | return str.trim(); 1320 | }).filter(function(str) { 1321 | return str.length; 1322 | }).join('-'); 1323 | if (!str.length) { 1324 | return ''; 1325 | } 1326 | if (str.length === 1) { 1327 | return str; 1328 | } 1329 | if (!(/[_.\- ]+/).test(str)) { 1330 | if (str === str.toUpperCase()) { 1331 | return str.toLowerCase(); 1332 | } 1333 | if (str[0] !== str[0].toLowerCase()) { 1334 | return str[0].toLowerCase() + str.slice(1); 1335 | } 1336 | return str; 1337 | } 1338 | str = preserveCamelCase(str); 1339 | return str.replace(/^[_.\- ]+/, '').toLowerCase().replace(/[_.\- ]+(\w|$)/g, function(m, p1) { 1340 | return p1.toUpperCase(); 1341 | }); 1342 | }; 1343 | return module.exports; 1344 | }); 1345 | 1346 | System.registerDynamic("angular2-polyfill/src/utils", ["dot-prop", "camelcase", "./core/core"], true, function($__require, exports, module) { 1347 | "use strict"; 1348 | ; 1349 | var define, 1350 | global = this, 1351 | GLOBAL = this; 1352 | var dotProp = $__require('dot-prop'); 1353 | var camelcase = $__require('camelcase'); 1354 | var core_1 = $__require('./core/core'); 1355 | function annotate(target, key, value) { 1356 | if (!target.__annotations__) { 1357 | target.__annotations__ = {}; 1358 | } 1359 | dotProp.set(target.__annotations__, key, value); 1360 | } 1361 | exports.annotate = annotate; 1362 | function toInjectorName(token) { 1363 | if (typeof token === 'string') { 1364 | return token; 1365 | } 1366 | if (token instanceof core_1.OpaqueToken) { 1367 | return camelcase(token.toString()); 1368 | } 1369 | return token.name; 1370 | } 1371 | exports.toInjectorName = toInjectorName; 1372 | return module.exports; 1373 | }); 1374 | 1375 | System.registerDynamic("angular2-polyfill/src/core/classes/injector", ["../../utils"], true, function($__require, exports, module) { 1376 | "use strict"; 1377 | ; 1378 | var define, 1379 | global = this, 1380 | GLOBAL = this; 1381 | var utils_1 = $__require('../../utils'); 1382 | var Injector = (function() { 1383 | function Injector() { 1384 | this._injector = angular.element(document).injector(); 1385 | } 1386 | Injector.prototype.get = function(token) { 1387 | var name = utils_1.toInjectorName(token); 1388 | return this._injector.get(name); 1389 | }; 1390 | Injector.prototype.getOptional = function(token) { 1391 | try { 1392 | var name_1 = utils_1.toInjectorName(token); 1393 | return this._injector.get(name_1); 1394 | } catch (err) { 1395 | return null; 1396 | } 1397 | }; 1398 | return Injector; 1399 | }()); 1400 | exports.Injector = Injector; 1401 | return module.exports; 1402 | }); 1403 | 1404 | System.registerDynamic("angular2-polyfill/src/core/classes/opaque_token", [], true, function($__require, exports, module) { 1405 | "use strict"; 1406 | ; 1407 | var define, 1408 | global = this, 1409 | GLOBAL = this; 1410 | var OpaqueToken = (function() { 1411 | function OpaqueToken(_desc) { 1412 | this._desc = _desc; 1413 | } 1414 | OpaqueToken.prototype.toString = function() { 1415 | return "Token " + this._desc; 1416 | }; 1417 | return OpaqueToken; 1418 | }()); 1419 | exports.OpaqueToken = OpaqueToken; 1420 | return module.exports; 1421 | }); 1422 | 1423 | System.registerDynamic("angular2-polyfill/src/core/classes/event_emitter", ["rxjs"], true, function($__require, exports, module) { 1424 | "use strict"; 1425 | ; 1426 | var define, 1427 | global = this, 1428 | GLOBAL = this; 1429 | var __extends = (this && this.__extends) || function(d, b) { 1430 | for (var p in b) 1431 | if (b.hasOwnProperty(p)) 1432 | d[p] = b[p]; 1433 | function __() { 1434 | this.constructor = d; 1435 | } 1436 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 1437 | }; 1438 | var rxjs_1 = $__require('rxjs'); 1439 | var EventEmitter = (function(_super) { 1440 | __extends(EventEmitter, _super); 1441 | function EventEmitter(isAsync) { 1442 | if (isAsync === void 0) { 1443 | isAsync = true; 1444 | } 1445 | _super.call(this); 1446 | this._isAsync = isAsync; 1447 | } 1448 | EventEmitter.prototype.emit = function(value) { 1449 | _super.prototype.next.call(this, value); 1450 | }; 1451 | EventEmitter.prototype.next = function(value) { 1452 | _super.prototype.next.call(this, value); 1453 | }; 1454 | EventEmitter.prototype.subscribe = function(generatorOrNext, error, complete) { 1455 | var schedulerFn; 1456 | var errorFn = function(err) { 1457 | return null; 1458 | }; 1459 | var completeFn = function() { 1460 | return null; 1461 | }; 1462 | if (generatorOrNext && typeof generatorOrNext === 'object') { 1463 | schedulerFn = this._isAsync ? function(value) { 1464 | setTimeout(function() { 1465 | return generatorOrNext.next(value); 1466 | }); 1467 | } : function(value) { 1468 | generatorOrNext.next(value); 1469 | }; 1470 | if (generatorOrNext.error) { 1471 | errorFn = this._isAsync ? function(err) { 1472 | setTimeout(function() { 1473 | return generatorOrNext.error(err); 1474 | }); 1475 | } : function(err) { 1476 | generatorOrNext.error(err); 1477 | }; 1478 | } 1479 | if (generatorOrNext.complete) { 1480 | completeFn = this._isAsync ? function() { 1481 | setTimeout(function() { 1482 | return generatorOrNext.complete(); 1483 | }); 1484 | } : function() { 1485 | generatorOrNext.complete(); 1486 | }; 1487 | } 1488 | } else { 1489 | schedulerFn = this._isAsync ? function(value) { 1490 | setTimeout(function() { 1491 | return generatorOrNext(value); 1492 | }); 1493 | } : function(value) { 1494 | generatorOrNext(value); 1495 | }; 1496 | if (error) { 1497 | errorFn = this._isAsync ? function(err) { 1498 | setTimeout(function() { 1499 | return error(err); 1500 | }); 1501 | } : function(err) { 1502 | error(err); 1503 | }; 1504 | } 1505 | if (complete) { 1506 | completeFn = this._isAsync ? function() { 1507 | setTimeout(function() { 1508 | return complete(); 1509 | }); 1510 | } : function() { 1511 | complete(); 1512 | }; 1513 | } 1514 | } 1515 | return _super.prototype.subscribe.call(this, schedulerFn, errorFn, completeFn); 1516 | }; 1517 | return EventEmitter; 1518 | }(rxjs_1.Subject)); 1519 | exports.EventEmitter = EventEmitter; 1520 | return module.exports; 1521 | }); 1522 | 1523 | System.registerDynamic("angular2-polyfill/src/core/core", ["./decorators/Component", "./decorators/Directive", "./decorators/Inject", "./decorators/Injectable", "./decorators/Input", "./decorators/Output", "./decorators/Pipe", "./decorators/Optional", "./functions/provide", "./classes/provider", "./classes/injector", "./classes/opaque_token", "./classes/event_emitter"], true, function($__require, exports, module) { 1524 | "use strict"; 1525 | ; 1526 | var define, 1527 | global = this, 1528 | GLOBAL = this; 1529 | var Component_1 = $__require('./decorators/Component'); 1530 | exports.Component = Component_1.Component; 1531 | var Directive_1 = $__require('./decorators/Directive'); 1532 | exports.Directive = Directive_1.Directive; 1533 | var Inject_1 = $__require('./decorators/Inject'); 1534 | exports.Inject = Inject_1.Inject; 1535 | var Injectable_1 = $__require('./decorators/Injectable'); 1536 | exports.Injectable = Injectable_1.Injectable; 1537 | var Input_1 = $__require('./decorators/Input'); 1538 | exports.Input = Input_1.Input; 1539 | var Output_1 = $__require('./decorators/Output'); 1540 | exports.Output = Output_1.Output; 1541 | var Pipe_1 = $__require('./decorators/Pipe'); 1542 | exports.Pipe = Pipe_1.Pipe; 1543 | var Optional_1 = $__require('./decorators/Optional'); 1544 | exports.Optional = Optional_1.Optional; 1545 | var provide_1 = $__require('./functions/provide'); 1546 | exports.provide = provide_1.provide; 1547 | var provider_1 = $__require('./classes/provider'); 1548 | exports.Provider = provider_1.Provider; 1549 | var injector_1 = $__require('./classes/injector'); 1550 | exports.Injector = injector_1.Injector; 1551 | var opaque_token_1 = $__require('./classes/opaque_token'); 1552 | exports.OpaqueToken = opaque_token_1.OpaqueToken; 1553 | var event_emitter_1 = $__require('./classes/event_emitter'); 1554 | exports.EventEmitter = event_emitter_1.EventEmitter; 1555 | return module.exports; 1556 | }); 1557 | 1558 | System.registerDynamic("angular2-polyfill/core", ["./src/core/core"], true, function($__require, exports, module) { 1559 | "use strict"; 1560 | ; 1561 | var define, 1562 | global = this, 1563 | GLOBAL = this; 1564 | function __export(m) { 1565 | for (var p in m) 1566 | if (!exports.hasOwnProperty(p)) 1567 | exports[p] = m[p]; 1568 | } 1569 | __export($__require('./src/core/core')); 1570 | return module.exports; 1571 | }); 1572 | 1573 | System.registerDynamic("angular2-polyfill/src/router/instruction", ["../../core"], true, function($__require, exports, module) { 1574 | "use strict"; 1575 | ; 1576 | var define, 1577 | global = this, 1578 | GLOBAL = this; 1579 | var __decorate = (this && this.__decorate) || function(decorators, target, key, desc) { 1580 | var c = arguments.length, 1581 | r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, 1582 | d; 1583 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") 1584 | r = Reflect.decorate(decorators, target, key, desc); 1585 | else 1586 | for (var i = decorators.length - 1; i >= 0; i--) 1587 | if (d = decorators[i]) 1588 | r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 1589 | return c > 3 && r && Object.defineProperty(target, key, r), r; 1590 | }; 1591 | var __param = (this && this.__param) || function(paramIndex, decorator) { 1592 | return function(target, key) { 1593 | decorator(target, key, paramIndex); 1594 | }; 1595 | }; 1596 | var core_1 = $__require('../../core'); 1597 | var RouteParams = (function() { 1598 | function RouteParams(stateParams) { 1599 | this.stateParams = stateParams; 1600 | } 1601 | RouteParams.prototype.get = function(param) { 1602 | return this.stateParams[param]; 1603 | }; 1604 | RouteParams = __decorate([__param(0, core_1.Inject('$stateParams'))], RouteParams); 1605 | return RouteParams; 1606 | }()); 1607 | exports.RouteParams = RouteParams; 1608 | var Instruction = (function() { 1609 | function Instruction() {} 1610 | return Instruction; 1611 | }()); 1612 | exports.Instruction = Instruction; 1613 | return module.exports; 1614 | }); 1615 | 1616 | System.registerDynamic("angular2-polyfill/src/router/providers", ["./router", "./instruction"], true, function($__require, exports, module) { 1617 | "use strict"; 1618 | ; 1619 | var define, 1620 | global = this, 1621 | GLOBAL = this; 1622 | var router_1 = $__require('./router'); 1623 | var instruction_1 = $__require('./instruction'); 1624 | exports.ROUTER_PROVIDERS = [router_1.Router, instruction_1.RouteParams]; 1625 | return module.exports; 1626 | }); 1627 | 1628 | System.registerDynamic("angular2-polyfill/router", ["./src/router/router", "./src/router/instruction", "./src/router/decorators/RouteConfig", "./src/router/lifecycle/lifecycle_annotations", "./src/router/providers"], true, function($__require, exports, module) { 1629 | "use strict"; 1630 | ; 1631 | var define, 1632 | global = this, 1633 | GLOBAL = this; 1634 | var router_1 = $__require('./src/router/router'); 1635 | exports.Router = router_1.Router; 1636 | var instruction_1 = $__require('./src/router/instruction'); 1637 | exports.RouteParams = instruction_1.RouteParams; 1638 | var instruction_2 = $__require('./src/router/instruction'); 1639 | exports.Instruction = instruction_2.Instruction; 1640 | var RouteConfig_1 = $__require('./src/router/decorators/RouteConfig'); 1641 | exports.RouteConfig = RouteConfig_1.RouteConfig; 1642 | var lifecycle_annotations_1 = $__require('./src/router/lifecycle/lifecycle_annotations'); 1643 | exports.CanActivate = lifecycle_annotations_1.CanActivate; 1644 | var providers_1 = $__require('./src/router/providers'); 1645 | exports.ROUTER_PROVIDERS = providers_1.ROUTER_PROVIDERS; 1646 | return module.exports; 1647 | }); 1648 | 1649 | //# sourceMappingURL=angular2-polyfill.js.map -------------------------------------------------------------------------------- /angular2-polyfill/core.ts: -------------------------------------------------------------------------------- 1 | export * from './src/core/core'; 2 | -------------------------------------------------------------------------------- /angular2-polyfill/http.ts: -------------------------------------------------------------------------------- 1 | export {Http} from './src/http/http.service'; 2 | 3 | export {HTTP_PROVIDERS} from './src/http/providers'; 4 | -------------------------------------------------------------------------------- /angular2-polyfill/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular2-polyfill", 3 | "version": "0.0.32", 4 | "description": "Angular2 polyfill for Angular1", 5 | "license": "MIT", 6 | "repository": "SamVerschueren/angular2-polyfill", 7 | "author": { 8 | "name": "Sam Verschueren", 9 | "email": "sam.verschueren@gmail.com", 10 | "url": "github.com/SamVerschueren" 11 | }, 12 | "typings": "bundles/angular2-polyfill.d.ts", 13 | "main": false, 14 | "scripts": { 15 | "prepublish": "cd .. && npm run build" 16 | }, 17 | "peerDependencies": { 18 | "reflect-metadata": "0.1.3", 19 | "rxjs": "5.0.0-beta.6" 20 | }, 21 | "dependencies": { 22 | "camelcase": "^2.1.1", 23 | "decamelize": "^1.2.0", 24 | "dot-prop": "^2.4.0" 25 | }, 26 | "devDependencies": { 27 | "rxjs": "5.0.0-beta.6" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /angular2-polyfill/platform/browser.ts: -------------------------------------------------------------------------------- 1 | export function bootstrap(base) { 2 | throw new Error('Not implemented yet. Please use `angular2-polyfill/platform/upgrade` for now.'); 3 | } 4 | -------------------------------------------------------------------------------- /angular2-polyfill/platform/upgrade.ts: -------------------------------------------------------------------------------- 1 | export {bootstrap} from '../src/platform/upgrade'; 2 | -------------------------------------------------------------------------------- /angular2-polyfill/router-deprecated.ts: -------------------------------------------------------------------------------- 1 | export {Router} from './src/router-deprecated/router'; 2 | export {RouteParams} from './src/router-deprecated/instruction'; 3 | export {Instruction} from './src/router-deprecated/instruction'; 4 | export {RouteConfig} from './src/router-deprecated/decorators/RouteConfig'; 5 | export {CanActivate} from './src/router-deprecated/lifecycle/lifecycle_annotations'; 6 | export * from './src/router-deprecated/interfaces'; 7 | 8 | export {ROUTER_PROVIDERS} from './src/router-deprecated/providers'; 9 | -------------------------------------------------------------------------------- /angular2-polyfill/src/common/common.ts: -------------------------------------------------------------------------------- 1 | import {AsyncPipe} from './pipes/async.pipe'; 2 | import * as utils from '../platform/bootstrap/index'; 3 | 4 | export function bootstrap(ngModule) { 5 | utils.bootstrap(ngModule, [AsyncPipe]); 6 | } 7 | -------------------------------------------------------------------------------- /angular2-polyfill/src/common/pipes/async.pipe.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Thanks to @cvuorinen for the angular1-async-filter 3 | * https://github.com/cvuorinen/angular1-async-filter 4 | */ 5 | import {Pipe, PipeTransform} from '../../core/core'; 6 | 7 | @Pipe({name: 'async', pure: false}) 8 | export class AsyncPipe implements PipeTransform { 9 | 10 | private static currentObjectID: number = 0; 11 | private static values: any = {}; 12 | private static subscriptions: any = {}; 13 | 14 | constructor() { 15 | 16 | } 17 | 18 | static objectId(obj) { 19 | if (!obj.hasOwnProperty('__asyncFilterObjectID__')) { 20 | obj.__asyncFilterObjectID__ = ++AsyncPipe.currentObjectID; 21 | } 22 | 23 | return obj.__asyncFilterObjectID__; 24 | } 25 | 26 | transform(input, [scope]) { 27 | if (!input || !(input.subscribe || input.then)) { 28 | return input; 29 | } 30 | 31 | const inputId = AsyncPipe.objectId(input); 32 | if (!(inputId in AsyncPipe.subscriptions)) { 33 | const subscriptionStrategy = input.subscribe && input.subscribe.bind(input) 34 | || input.success && input.success.bind(input) // To make it work with HttpPromise 35 | || input.then.bind(input); 36 | 37 | AsyncPipe.subscriptions[inputId] = subscriptionStrategy(value => { 38 | AsyncPipe.values[inputId] = value; 39 | 40 | if (scope && scope.$applyAsync) { 41 | scope.$applyAsync(); // Automatic safe apply, if scope provided 42 | } 43 | }); 44 | } 45 | 46 | return AsyncPipe.values[inputId] || undefined; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /angular2-polyfill/src/core/classes/event_emitter.ts: -------------------------------------------------------------------------------- 1 | import {Subject} from 'rxjs'; 2 | 3 | export class EventEmitter extends Subject { 4 | 5 | private _isAsync: boolean; 6 | 7 | constructor(isAsync: boolean = true) { 8 | super(); 9 | this._isAsync = isAsync; 10 | } 11 | 12 | emit(value: T) { 13 | super.next(value); 14 | } 15 | 16 | /** 17 | * @deprecated - use .emit(value) instead 18 | */ 19 | next(value: any) { 20 | super.next(value); 21 | } 22 | 23 | subscribe(generatorOrNext?: any, error?: any, complete?: any): any { 24 | let schedulerFn; 25 | let errorFn = (err: any) => null; 26 | let completeFn = () => null; 27 | 28 | if (generatorOrNext && typeof generatorOrNext === 'object') { 29 | schedulerFn = this._isAsync ? value => { setTimeout(() => generatorOrNext.next(value)); } : value => { generatorOrNext.next(value); }; 30 | 31 | if (generatorOrNext.error) { 32 | errorFn = this._isAsync ? err => { setTimeout(() => generatorOrNext.error(err)); } : err => { generatorOrNext.error(err); }; 33 | } 34 | 35 | if (generatorOrNext.complete) { 36 | completeFn = this._isAsync ? () => { setTimeout(() => generatorOrNext.complete()); } : () => { generatorOrNext.complete(); }; 37 | } 38 | } else { 39 | schedulerFn = this._isAsync ? value => { setTimeout(() => generatorOrNext(value)); } : value => { generatorOrNext(value); }; 40 | 41 | if (error) { 42 | errorFn = this._isAsync ? err => { setTimeout(() => error(err)); } : err => { error(err); }; 43 | } 44 | 45 | if (complete) { 46 | completeFn = this._isAsync ? () => { setTimeout(() => complete()); } : () => { complete(); }; 47 | } 48 | } 49 | 50 | return super.subscribe(schedulerFn, errorFn, completeFn); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /angular2-polyfill/src/core/classes/injector.ts: -------------------------------------------------------------------------------- 1 | import * as camelcase from 'camelcase'; 2 | import {OpaqueToken} from '../classes/opaque_token'; 3 | import {toInjectorName} from '../../utils'; 4 | 5 | export class Injector { 6 | 7 | private _injector: ng.auto.IInjectorService; 8 | 9 | constructor() { 10 | this._injector = angular.element(document).injector(); 11 | } 12 | 13 | get(token: any) { 14 | const name = toInjectorName(token); 15 | return this._injector.get(name); 16 | } 17 | 18 | getOptional(token: any) { 19 | try { 20 | const name = toInjectorName(token); 21 | return this._injector.get(name); 22 | } catch (err) { 23 | return null; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /angular2-polyfill/src/core/classes/opaque_token.ts: -------------------------------------------------------------------------------- 1 | export class OpaqueToken { 2 | static id: number = 0; 3 | 4 | private _id: number; 5 | 6 | constructor(private _desc: string) { 7 | this._id = OpaqueToken.id++; 8 | } 9 | 10 | toString(): string { 11 | return `Token ${this._desc} (${this._id})`; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /angular2-polyfill/src/core/classes/provider.ts: -------------------------------------------------------------------------------- 1 | import {ProviderMetadata} from '../interfaces/ProviderMetadata'; 2 | 3 | export class Provider { 4 | 5 | token: any; 6 | useClass: any; 7 | useValue: any; 8 | useExisting: any; 9 | useFactory: Function; 10 | deps: any[]; 11 | multi: boolean; 12 | 13 | constructor(token: any, options: ProviderMetadata) { 14 | this.token = token; 15 | this.useClass = options.useClass; 16 | this.useValue = options.useValue; 17 | this.useExisting = options.useExisting; 18 | this.useFactory = options.useFactory; 19 | this.deps = options.deps; 20 | this.multi = options.multi; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /angular2-polyfill/src/core/core.ts: -------------------------------------------------------------------------------- 1 | export {Component} from './decorators/Component'; 2 | export {Directive} from './decorators/Directive'; 3 | export {Inject} from './decorators/Inject'; 4 | export {Injectable} from './decorators/Injectable'; 5 | export {Input} from './decorators/Input'; 6 | export {Output} from './decorators/Output'; 7 | export {Pipe} from './decorators/Pipe'; 8 | export {Optional} from './decorators/Optional'; 9 | 10 | export {provide} from './functions/provide'; 11 | 12 | export {Provider} from './classes/provider'; 13 | export {Injector} from './classes/injector'; 14 | export {OpaqueToken} from './classes/opaque_token'; 15 | export {EventEmitter} from './classes/event_emitter'; 16 | 17 | export {OnInit} from './interfaces/OnInit'; 18 | export {OnDestroy} from './interfaces/OnDestroy'; 19 | 20 | export {PipeTransform} from './interfaces/PipeTransform'; 21 | -------------------------------------------------------------------------------- /angular2-polyfill/src/core/decorators/Component.ts: -------------------------------------------------------------------------------- 1 | import {ComponentMetadata} from '../interfaces/ComponentMetadata'; 2 | import {annotate} from '../../utils'; 3 | 4 | export function Component(component: ComponentMetadata) { 5 | return (target: any) => { 6 | annotate(target, 'component', component); 7 | }; 8 | } 9 | -------------------------------------------------------------------------------- /angular2-polyfill/src/core/decorators/Directive.ts: -------------------------------------------------------------------------------- 1 | import {DirectiveMetadata} from '../interfaces/DirectiveMetadata'; 2 | import {annotate} from '../../utils'; 3 | 4 | export function Directive(options: DirectiveMetadata) { 5 | return (target: any) => { 6 | annotate(target, 'directive', options); 7 | }; 8 | } 9 | -------------------------------------------------------------------------------- /angular2-polyfill/src/core/decorators/Inject.ts: -------------------------------------------------------------------------------- 1 | export function Inject(token: any) { 2 | return (target: any, propertyKey: string | symbol, parameterIndex: number) => { 3 | if (!target.__annotations__) { 4 | target.__annotations__ = {}; 5 | } 6 | 7 | if (!target.__annotations__.inject) { 8 | target.__annotations__.inject = []; 9 | } 10 | 11 | target.__annotations__.inject[parameterIndex] = token; 12 | }; 13 | } 14 | -------------------------------------------------------------------------------- /angular2-polyfill/src/core/decorators/Injectable.ts: -------------------------------------------------------------------------------- 1 | import {annotate} from '../../utils'; 2 | 3 | export function Injectable() { 4 | return (target: any) => { 5 | annotate(target, 'injectable', true); 6 | }; 7 | } 8 | -------------------------------------------------------------------------------- /angular2-polyfill/src/core/decorators/Input.ts: -------------------------------------------------------------------------------- 1 | import {annotate} from '../../utils'; 2 | 3 | export function Input(bindingPropertyName?: string) { 4 | return (target: any, propertyKey: string) => { 5 | annotate(target.constructor, `inputs.${propertyKey}`, bindingPropertyName || propertyKey); 6 | }; 7 | } 8 | -------------------------------------------------------------------------------- /angular2-polyfill/src/core/decorators/Optional.ts: -------------------------------------------------------------------------------- 1 | export function Optional() { 2 | return (target: any, propertyKey: string | symbol, parameterIndex: number) => { 3 | if (!target.__annotations__) { 4 | target.__annotations__ = {}; 5 | } 6 | 7 | target.__annotations__.optional = {}; 8 | target.__annotations__.optional[parameterIndex] = true; 9 | }; 10 | } 11 | -------------------------------------------------------------------------------- /angular2-polyfill/src/core/decorators/Output.ts: -------------------------------------------------------------------------------- 1 | import {annotate} from '../../utils'; 2 | 3 | export function Output(bindingPropertyName?: string) { 4 | return (target: any, propertyKey: string) => { 5 | annotate(target.constructor, `outputs.${propertyKey}`, bindingPropertyName || propertyKey); 6 | }; 7 | } 8 | -------------------------------------------------------------------------------- /angular2-polyfill/src/core/decorators/Pipe.ts: -------------------------------------------------------------------------------- 1 | import {PipeMetadata} from '../interfaces/PipeMetadata'; 2 | import {annotate} from '../../utils'; 3 | 4 | export function Pipe(pipe: PipeMetadata) { 5 | return (target: any) => { 6 | annotate(target, 'pipe', pipe); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /angular2-polyfill/src/core/functions/provide.ts: -------------------------------------------------------------------------------- 1 | import * as camelcase from 'camelcase'; 2 | import {Provider, OpaqueToken} from '../core'; 3 | import {ProviderMetadata} from '../interfaces/ProviderMetadata'; 4 | import {annotate, toInjectorName} from '../../utils'; 5 | 6 | export function provide(token: any, options: ProviderMetadata): Provider { 7 | return new Provider(token, options); 8 | } 9 | -------------------------------------------------------------------------------- /angular2-polyfill/src/core/interfaces/ComponentMetadata.ts: -------------------------------------------------------------------------------- 1 | export interface ComponentMetadata { 2 | selector?: string, 3 | inputs?: string[], 4 | outputs?: string[], 5 | host?: {[key: string]: string}, 6 | exportAs?: string, 7 | template?: string, 8 | templateUrl?: string, 9 | styles?: string[], 10 | styleUrls?: string[], 11 | directives?: any[], 12 | providers?: any[], 13 | pipes?: any[] 14 | } 15 | -------------------------------------------------------------------------------- /angular2-polyfill/src/core/interfaces/DirectiveMetadata.ts: -------------------------------------------------------------------------------- 1 | export interface DirectiveMetadata { 2 | selector?: string, 3 | inputs?: string[], 4 | outputs?: string[], 5 | host?: {[key: string]: string}, 6 | providers?: any[] 7 | } 8 | -------------------------------------------------------------------------------- /angular2-polyfill/src/core/interfaces/OnDestroy.ts: -------------------------------------------------------------------------------- 1 | export interface OnDestroy { 2 | ngOnDestroy(): void; 3 | } 4 | -------------------------------------------------------------------------------- /angular2-polyfill/src/core/interfaces/OnInit.ts: -------------------------------------------------------------------------------- 1 | export interface OnInit { 2 | ngOnInit(): void; 3 | } 4 | -------------------------------------------------------------------------------- /angular2-polyfill/src/core/interfaces/PipeMetadata.ts: -------------------------------------------------------------------------------- 1 | export interface PipeMetadata { 2 | name: string, 3 | pure?: boolean 4 | } 5 | -------------------------------------------------------------------------------- /angular2-polyfill/src/core/interfaces/PipeTransform.ts: -------------------------------------------------------------------------------- 1 | export interface PipeTransform { 2 | transform(value: any, ...args: any[]): any; 3 | } 4 | -------------------------------------------------------------------------------- /angular2-polyfill/src/core/interfaces/ProviderMetadata.ts: -------------------------------------------------------------------------------- 1 | export interface ProviderMetadata { 2 | useClass?: any, 3 | useValue?: any, 4 | useExisting?: any, 5 | useFactory?: Function, 6 | deps?: any[], 7 | multi?: boolean 8 | } 9 | -------------------------------------------------------------------------------- /angular2-polyfill/src/http/http.service.ts: -------------------------------------------------------------------------------- 1 | import {Observable} from 'rxjs'; 2 | import {Inject} from '../../core'; 3 | import {RequestOptionsArgs} from './interfaces/RequestOptionsArgs'; 4 | import {Response} from './interfaces/Response'; 5 | 6 | export class Http { 7 | 8 | // Inject good old `$http` 9 | constructor(@Inject('$http') private http) { 10 | 11 | } 12 | 13 | // // TODO IMPLEMENT 14 | // request(url: string | Request, options?: RequestOptionsArgs): Promise { 15 | // 16 | // } 17 | 18 | get(url: string, options?: RequestOptionsArgs): Observable { 19 | return Observable.fromPromise(this.http.get(url, options)); 20 | } 21 | 22 | post(url: string, body: any, options?: RequestOptionsArgs): Observable { 23 | return Observable.fromPromise(this.http.post(url, body, options)); 24 | } 25 | 26 | put(url: string, body: any, options?: RequestOptionsArgs): Observable { 27 | return Observable.fromPromise(this.http.put(url, body, options)); 28 | } 29 | 30 | delete(url: string, options?: RequestOptionsArgs): Observable { 31 | return Observable.fromPromise(this.http.delete(url, options)); 32 | } 33 | 34 | patch(url: string, body: any, options?: RequestOptionsArgs): Observable { 35 | return Observable.fromPromise(this.http.patch(url, body, options)); 36 | } 37 | 38 | head(url: string, options?: RequestOptionsArgs): Observable { 39 | return Observable.fromPromise(this.http.head(url, options)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /angular2-polyfill/src/http/interfaces/RequestOptionsArgs.ts: -------------------------------------------------------------------------------- 1 | export interface RequestOptionsArgs { 2 | params?: string | any; 3 | data?: string | any; 4 | headers?: any; 5 | xsrfHeaderName?: string; 6 | xsrfCookieName?: string; 7 | transformRequest?: Function | Function[]; 8 | transformResponse?: Function | Function[]; 9 | paramSerializer?: string | Function; 10 | cache?: boolean | any; 11 | timeout?: number | Promise; 12 | withCredentials?: boolean; 13 | responseType?: string; 14 | } 15 | -------------------------------------------------------------------------------- /angular2-polyfill/src/http/interfaces/Response.ts: -------------------------------------------------------------------------------- 1 | import {RequestOptionsArgs} from './RequestOptionsArgs'; 2 | 3 | export interface Response { 4 | data: string | any; 5 | status: number; 6 | headers: Function; 7 | config: RequestOptionsArgs; 8 | statusText: string; 9 | } 10 | -------------------------------------------------------------------------------- /angular2-polyfill/src/http/providers.ts: -------------------------------------------------------------------------------- 1 | import {Http} from './http.service'; 2 | 3 | // Export the providers 4 | export const HTTP_PROVIDERS = [Http]; 5 | -------------------------------------------------------------------------------- /angular2-polyfill/src/platform/bootstrap/component.ts: -------------------------------------------------------------------------------- 1 | import * as camelcase from 'camelcase'; 2 | import * as decamelize from 'decamelize'; 3 | import {Router} from '../../router-deprecated/router'; 4 | import * as utils from './index'; 5 | import * as host from '../utils/host'; 6 | import * as injector from '../utils/injector'; 7 | import * as input from '../utils/input'; 8 | import * as output from '../utils/output'; 9 | 10 | let map = {}; 11 | const states = {}; 12 | 13 | export function bootstrap(ngModule, target, parentState?: any) { 14 | const annotations = target.__annotations__; 15 | const component = annotations.component; 16 | const name = camelcase(component.selector || target.name); 17 | const styleElements: any[] = []; 18 | const headEl = angular.element(document).find('head'); 19 | 20 | if (map[target.name]) { 21 | return name; 22 | } 23 | 24 | map[target.name] = decamelize(component.selector || target.name, '-'); 25 | 26 | // Bootstrap providers, directives and pipes 27 | (component.providers || []).forEach(provider => utils.bootstrap(ngModule, provider)); 28 | (component.directives || []).forEach(directive => utils.bootstrap(ngModule, directive)); 29 | (component.pipes || []).forEach(pipe => utils.bootstrap(ngModule, pipe)); 30 | 31 | // Define the style elements 32 | (component.styles || []).forEach(style => { 33 | styleElements.push(angular.element('')); 34 | }); 35 | (component.styleUrls || []).forEach(url => { 36 | styleElements.push(angular.element('')); 37 | }); 38 | 39 | // Inject the services 40 | injector.inject(ngModule, target); 41 | 42 | const hostBindings = host.parse(component.host || {}); 43 | 44 | ngModule 45 | .controller(target.name, target) 46 | .directive(name, ['$rootScope', '$compile', ($rootScope, $compile) => { 47 | const directive: any = { 48 | restrict: 'E', 49 | scope: {}, 50 | bindToController: {}, 51 | controller: target.name, 52 | controllerAs: component.exportAs || '$ctrl', 53 | transclude: true, 54 | compile: () => { 55 | return { 56 | pre: (scope, el) => { 57 | // Prepend all the style elements to the `head` dom element 58 | styleElements.forEach(el => headEl.prepend(el)); 59 | 60 | // Bind the hosts 61 | host.bind(scope, el, hostBindings, component.controllerAs); 62 | 63 | if (target.prototype.ngOnInit) { 64 | // Call the `ngOnInit` lifecycle hook 65 | const init = $compile(`
`)(scope); 66 | el.append(init); 67 | } 68 | 69 | scope.$on('$destroy', () => { 70 | // Remove all the style elements when destroying the directive 71 | styleElements.forEach(el => el.remove()); 72 | 73 | if (target.prototype.ngOnDestroy) { 74 | // Call the `ngOnDestroy` lifecycle hook 75 | scope[directive.controllerAs].ngOnDestroy(); 76 | } 77 | }); 78 | } 79 | } 80 | } 81 | }; 82 | 83 | // Bind inputs and outputs 84 | input.bind(target, directive); 85 | output.bind($rootScope, target, directive); 86 | 87 | // Set the template 88 | if (component.template) { 89 | directive.template = component.template; 90 | } else { 91 | directive.templateUrl = component.templateUrl; 92 | } 93 | 94 | return directive; 95 | }]); 96 | 97 | if (annotations.routes) { 98 | const cmpStates = []; 99 | 100 | annotations.routes.forEach(route => { 101 | const name = route.name || route.as; 102 | const routerAnnotations = route.component.__annotations__ && route.component.__annotations__.router; 103 | 104 | const state: any = { 105 | name, 106 | url: route.path, 107 | isDefault: route.useAsDefault === true 108 | } 109 | 110 | // Bootstrap the route component if it's not the same as the target component 111 | if (route.component.name !== target.name) { 112 | bootstrap(ngModule, route.component, state); 113 | } 114 | 115 | // If the url ends with `/...` this is a non-terminal route and thus is abstract. 116 | if (state.url.substr(-4) === '/...') { 117 | state.url = state.url.substr(0, state.url.length - 4); 118 | state.abstract = true; 119 | } 120 | 121 | // Set the `parent` property if the parent is a non-terminal route 122 | if (parentState && parentState.url && parentState.url.substr(-4) === '/...') { 123 | state.parent = parentState.name; 124 | } 125 | 126 | // Set the template after we are sure the component has been bootstrapped 127 | state.template = `<${map[route.component.name]}>`; 128 | 129 | // Push the state to the component states 130 | cmpStates.push(state.name); 131 | 132 | // Keep track of all the application states 133 | states[name] = state; 134 | 135 | // Attach CanActivate router hook 136 | if (routerAnnotations && routerAnnotations.canActivate) { 137 | const hook: any[] = ['Router', '$state', '$stateParams']; 138 | 139 | if (Object.keys(routerAnnotations.canActivate.prototype).length > 0) { 140 | if (!routerAnnotations.canActivate.prototype.routerCanActivate) { 141 | throw new Error('@CanActivate class does not implement the `CanActivate` interface.'); 142 | } 143 | 144 | hook.push(utils.bootstrap(ngModule, routerAnnotations.canActivate)); 145 | } 146 | 147 | hook.push((router: Router, $state, $stateParams, handler) => { 148 | const fn: Function = handler ? handler.routerCanActivate : routerAnnotations.canActivate; 149 | 150 | // Generate instructions for the previous and next state 151 | return Promise.all([ 152 | router.generate([name, $stateParams]), 153 | $state.current.name.length === 0 ? null : router.generate([$state.current.name, $state.params]) 154 | ]).then(instructions => { 155 | // Call the routerCanActivate hook with the instructions 156 | return Promise.resolve(fn.apply(handler, instructions)); 157 | }).then(result => { 158 | if (!result) { 159 | // Reject if the result is false 160 | return Promise.reject('could not activate'); 161 | } 162 | }); 163 | }); 164 | 165 | states[name].resolve = { 166 | routerCanActivate: hook 167 | }; 168 | } 169 | }); 170 | 171 | ngModule.config(['$urlRouterProvider', '$stateProvider', ($urlRouterProvider, $stateProvider) => { 172 | cmpStates.forEach(name => { 173 | const state = states[name]; 174 | $stateProvider.state(name, state); 175 | 176 | if (state.isDefault) { 177 | if (state.parent) { 178 | let parentState = states[state.parent]; 179 | let from = parentState.url; 180 | 181 | while (parentState.parent) { 182 | parentState = states[parentState.parent]; 183 | from = parentState.url + from; 184 | } 185 | 186 | $urlRouterProvider.when(from, from + state.url); 187 | } else { 188 | $urlRouterProvider.otherwise(state.url); 189 | } 190 | } 191 | }); 192 | }]) 193 | } 194 | 195 | return name; 196 | } 197 | -------------------------------------------------------------------------------- /angular2-polyfill/src/platform/bootstrap/core.ts: -------------------------------------------------------------------------------- 1 | let bootstrapped = false; 2 | 3 | export function bootstrap(ngModule) { 4 | if (bootstrapped) { 5 | return; 6 | } 7 | 8 | bootstrapped = true; 9 | 10 | ngModule.run(['$q', '$window', ($q, $window) => { 11 | // Create an Angular aware global Promise object 12 | $window.Promise = executor => { 13 | return $q(executor); 14 | }; 15 | 16 | $window.Promise.all = $q.all.bind($q); 17 | $window.Promise.reject = $q.reject.bind($q); 18 | $window.Promise.resolve = $q.when.bind($q); 19 | 20 | $window.Promise.race = promises => { 21 | let promiseMgr = $q.defer(); 22 | 23 | const resolve = result => { 24 | if (promiseMgr) { 25 | promiseMgr.resolve(result); 26 | promiseMgr = null; 27 | } 28 | }; 29 | 30 | const reject = err => { 31 | if (promiseMgr) { 32 | promiseMgr.reject(err); 33 | promiseMgr = null; 34 | } 35 | }; 36 | 37 | for (let i = 0; i < promises.length; i++) { 38 | promises[i] 39 | .then(resolve) 40 | .catch(reject); 41 | } 42 | 43 | return promiseMgr.promise; 44 | }; 45 | }]); 46 | 47 | angular.element(document).ready(() => { 48 | angular.bootstrap(document, [ngModule.name]); 49 | }); 50 | } 51 | -------------------------------------------------------------------------------- /angular2-polyfill/src/platform/bootstrap/directive.ts: -------------------------------------------------------------------------------- 1 | import * as host from '../utils/host'; 2 | import * as injector from '../utils/injector'; 3 | import * as input from '../utils/input'; 4 | import * as output from '../utils/output'; 5 | 6 | function parseSelector(selector: string) { 7 | const regex = [ 8 | // {key: 'E', value: /^([a-zA-Z])$/}, 9 | {key: 'A', value: /^\[([a-zA-Z]+)\]$/}, 10 | {key: 'C', value: /^\.([a-zA-Z]+)$/} 11 | ]; 12 | 13 | for (let i = 0; i < regex.length; i++) { 14 | const result = selector.match(regex[i].value); 15 | 16 | if (result !== null) { 17 | return {restrict: regex[i].key, name: result[1]}; 18 | } 19 | }; 20 | 21 | throw new Error(`Selector ${selector} could not be parsed`); 22 | } 23 | 24 | export function bootstrap(ngModule, target) { 25 | const annotations = target.__annotations__; 26 | const directive = annotations.directive; 27 | 28 | const selector = parseSelector(directive.selector); 29 | const hostBindings = host.parse(directive.host || {}); 30 | 31 | // Inject the services 32 | injector.inject(ngModule, target); 33 | 34 | ngModule 35 | .controller(target.name, target) 36 | .directive(selector.name, ['$rootScope', ($rootScope) => { 37 | const declaration: any = { 38 | restrict: selector.restrict, 39 | scope: {}, 40 | bindToController: {}, 41 | controller: target.name, 42 | controllerAs: '$ctrl', 43 | link: (scope, el) => host.bind(scope, el, hostBindings) 44 | }; 45 | 46 | // Bind inputs and outputs 47 | input.bind(target, declaration); 48 | output.bind($rootScope, target, declaration); 49 | 50 | return declaration; 51 | }]); 52 | } 53 | -------------------------------------------------------------------------------- /angular2-polyfill/src/platform/bootstrap/factory.ts: -------------------------------------------------------------------------------- 1 | import * as injector from '../utils/injector'; 2 | import {bootstrapMultiFactory as bootstrapMulti} from './multi'; 3 | 4 | export function bootstrap(ngModule, target) { 5 | const annotations = target.__annotations__; 6 | const factory = annotations.factory; 7 | 8 | injector.inject(ngModule, target); 9 | 10 | const name = factory.name || target.name; 11 | 12 | if (annotations.multi === true) { 13 | bootstrapMulti(ngModule, name, target); 14 | } else { 15 | ngModule.factory(name, target); 16 | } 17 | 18 | return name; 19 | } 20 | -------------------------------------------------------------------------------- /angular2-polyfill/src/platform/bootstrap/index.ts: -------------------------------------------------------------------------------- 1 | import {Provider} from '../../core/core'; 2 | import {bootstrap as bootstrapComponent} from './component'; 3 | import {bootstrap as bootstrapDirective} from './directive'; 4 | import {bootstrap as bootstrapFactory} from './factory'; 5 | import {bootstrap as bootstrapPipe} from './pipe'; 6 | import {bootstrap as bootstrapValue} from './value'; 7 | import {bootstrap as bootstrapInjectable} from './injectable'; 8 | import {bootstrap as bootstrapProvider} from './provider'; 9 | 10 | export function bootstrap(ngModule, target): any { 11 | if (Array.isArray(target)) { 12 | return target.forEach(target => bootstrap(ngModule, target)); 13 | } 14 | 15 | if (target.__annotations__) { 16 | if (target.__annotations__.component) { 17 | return bootstrapComponent(ngModule, target); 18 | } else if (target.__annotations__.directive) { 19 | return bootstrapDirective(ngModule, target); 20 | } else if (target.__annotations__.factory) { 21 | return bootstrapFactory(ngModule, target); 22 | } else if (target.__annotations__.pipe) { 23 | return bootstrapPipe(ngModule, target); 24 | } else if (target.__annotations__.value) { 25 | return bootstrapValue(ngModule, target); 26 | } 27 | } 28 | 29 | if (target instanceof Provider) { 30 | return bootstrapProvider(ngModule, target); 31 | } 32 | 33 | return bootstrapInjectable(ngModule, target); 34 | } 35 | -------------------------------------------------------------------------------- /angular2-polyfill/src/platform/bootstrap/injectable.ts: -------------------------------------------------------------------------------- 1 | import * as injector from '../utils/injector'; 2 | import {bootstrapMultiInjectable as bootstrapMulti} from './multi'; 3 | 4 | export function bootstrap(ngModule, target) { 5 | const annotations = target.__annotations__ || {}; 6 | const injectable = annotations.injectable || {}; 7 | 8 | // DI 9 | injector.inject(ngModule, target); 10 | 11 | const name = injectable.name || target.name; 12 | 13 | if (annotations.multi === true) { 14 | bootstrapMulti(ngModule, name, target); 15 | } else { 16 | ngModule.service(name, target); 17 | } 18 | 19 | return name; 20 | } 21 | -------------------------------------------------------------------------------- /angular2-polyfill/src/platform/bootstrap/multi.ts: -------------------------------------------------------------------------------- 1 | let id = 0; 2 | const prefix = 'ng2Multi'; 3 | const map = {}; 4 | 5 | function bootstrapMulti(fn, ngModule, name, target) { 6 | map[name] = map[name] || []; 7 | 8 | // Create a unique name 9 | let privateName = `${prefix}_${fn}_${name}_${++id}`; 10 | ngModule[fn](privateName, target); 11 | 12 | // Add the name as dependency to the eventual result 13 | map[name].push(privateName); 14 | 15 | // Create a factory with the original name that returns all the other factories 16 | ngModule.factory(name, [...map[name], (...args) => args]); 17 | } 18 | 19 | export function bootstrapMultiFactory(ngModule, name, target) { 20 | bootstrapMulti('factory', ngModule, name, target); 21 | } 22 | 23 | export function bootstrapMultiInjectable(ngModule, name, target) { 24 | bootstrapMulti('service', ngModule, name, target); 25 | } 26 | 27 | export function bootstrapMultiValue(ngModule, name, target) { 28 | bootstrapMulti('value', ngModule, name, target); 29 | } 30 | -------------------------------------------------------------------------------- /angular2-polyfill/src/platform/bootstrap/pipe.ts: -------------------------------------------------------------------------------- 1 | import * as injector from '../utils/injector'; 2 | 3 | export function bootstrap(ngModule, target) { 4 | const pipe = target.__annotations__.pipe; 5 | injector.inject(ngModule, target); 6 | 7 | const filter = target.$inject || []; 8 | filter.push((...args) => { 9 | // Create a new instance and inject the dependencies 10 | const instance = new target(...args); 11 | 12 | // Create the filter function 13 | const filter: any = instance.transform; 14 | 15 | // If pure is set to false, it's a stateful filter 16 | filter.$stateful = pipe.pure === false; 17 | 18 | return filter; 19 | }); 20 | 21 | ngModule.filter(pipe.name, filter); 22 | return pipe.name; 23 | } 24 | -------------------------------------------------------------------------------- /angular2-polyfill/src/platform/bootstrap/provider.ts: -------------------------------------------------------------------------------- 1 | import {Provider} from '../../core/core'; 2 | import {toInjectorName, annotate} from '../../utils'; 3 | import * as utils from './index'; 4 | 5 | export function bootstrap(ngModule, provider: Provider) { 6 | let target: any = {}; 7 | 8 | const name = toInjectorName(provider.token); 9 | const inject = (provider.deps || []).map(toInjectorName); 10 | 11 | if (provider.useValue) { 12 | const value = provider.useValue; 13 | annotate(target, 'value', {name, value}); 14 | } else if (provider.useFactory) { 15 | target = provider.useFactory; 16 | annotate(target, 'factory', {name}); 17 | annotate(target, 'inject', inject); 18 | } else if (provider.useClass) { 19 | target = provider.useClass; 20 | annotate(target, 'injectable', {name}); 21 | } else if (provider.useExisting) { 22 | target = (v) => v; 23 | annotate(target, 'factory', {name}); 24 | annotate(target, 'inject', [toInjectorName(provider.useExisting)]); 25 | } 26 | 27 | annotate(target, 'multi', provider.multi); 28 | 29 | utils.bootstrap(ngModule, target); 30 | } 31 | -------------------------------------------------------------------------------- /angular2-polyfill/src/platform/bootstrap/value.ts: -------------------------------------------------------------------------------- 1 | import {bootstrapMultiValue as bootstrapMulti} from './multi'; 2 | 3 | export function bootstrap(ngModule, target) { 4 | const annotations = target.__annotations__; 5 | const value = annotations.value; 6 | const name = value.name; 7 | 8 | const ret = value.value; 9 | 10 | if (annotations.multi === true) { 11 | bootstrapMulti(ngModule, name, ret); 12 | } else { 13 | ngModule.value(name, ret); 14 | } 15 | 16 | return name; 17 | } 18 | -------------------------------------------------------------------------------- /angular2-polyfill/src/platform/upgrade.ts: -------------------------------------------------------------------------------- 1 | import {bootstrap as coreBootstrap} from './bootstrap/core'; 2 | import {bootstrap as commonBootstrap} from '../common/common'; 3 | import {bootstrap as bootstrapHelper} from './bootstrap/index'; 4 | import {Injector, provide} from '../core/core'; 5 | 6 | export function bootstrap(ngModule, component, providers: any[] = []) { 7 | // Bootstrap the core 8 | coreBootstrap(ngModule); 9 | 10 | // Bootstrap common components 11 | commonBootstrap(ngModule); 12 | 13 | // Bootstrap the injector 14 | bootstrapHelper(ngModule, provide(Injector, {useFactory: () => new Injector()})); 15 | 16 | // Bootstrap providers 17 | providers.forEach(provider => bootstrapHelper(ngModule, provider)); 18 | 19 | // Bootstrap the app tree 20 | bootstrapHelper(ngModule, component); 21 | } 22 | -------------------------------------------------------------------------------- /angular2-polyfill/src/platform/utils/host.ts: -------------------------------------------------------------------------------- 1 | import * as camelcase from 'camelcase'; 2 | import * as dotProp from 'dot-prop'; 3 | 4 | function parseHostBinding(key: string) { 5 | const regex = [ 6 | {type: 'attr', regex: /^([a-zA-Z]+)$/}, 7 | {type: 'prop', regex: /^\[([a-zA-Z\.-]+)\]$/}, 8 | {type: 'event', regex: /^\(([a-zA-Z]+)\)$/} 9 | ]; 10 | 11 | for (let i = 0; i < regex.length; i++) { 12 | const match = key.match(regex[i].regex); 13 | 14 | if (match !== null) { 15 | return {type: regex[i].type, value: match[1]}; 16 | } 17 | }; 18 | 19 | return {type: undefined, value: key}; 20 | } 21 | 22 | function applyValueToProperties(el: angular.IRootElementService, properties: any[], value: any) { 23 | properties.forEach(property => { 24 | const splitted = property.split('.'); 25 | 26 | if (splitted.length === 1) { 27 | // Set the property directly 28 | el.prop(camelcase(property), value); 29 | } else { 30 | const root = splitted.shift(); 31 | 32 | if (root === 'class') { 33 | // Handle adding/removing class names 34 | const method = value ? 'addClass' : 'removeClass'; 35 | el[method](splitted.join('.')); 36 | } else { 37 | // Handle deeply nested properties 38 | let runner = el.prop(camelcase(root)); 39 | while (splitted.length > 1) { 40 | runner = runner[camelcase(splitted.shift())]; 41 | } 42 | runner[camelcase(splitted.shift())] = value; 43 | } 44 | } 45 | }); 46 | } 47 | 48 | export function parse(hostBindings: {string: string}[]) { 49 | const result = { 50 | attrs: {}, 51 | events: {}, 52 | props: { 53 | raw: {}, 54 | expressions: {} 55 | } 56 | }; 57 | 58 | Object.keys(hostBindings).forEach(key => { 59 | let value = hostBindings[key]; 60 | const parsed = parseHostBinding(key); 61 | 62 | if (parsed.type === 'attr') { 63 | result.attrs[parsed.value] = value; 64 | } else if (parsed.type === 'event') { 65 | const handler = value.match(/^([a-zA-Z]+)\((.*?)\)$/); 66 | 67 | const method = handler[1]; 68 | const params = handler[2].length === 0 ? [] : handler[2].split(/,[ ]*/); 69 | 70 | result.events[parsed.value] = {method, params}; 71 | } else if (parsed.type === 'prop') { 72 | const raw = value.match(/^['"](.*?)['"]$/); 73 | let map = 'expressions'; 74 | 75 | if (raw) { 76 | // If the value is escaped, it's a raw value and should be applied directly 77 | value = raw[1]; 78 | map = 'raw'; 79 | } 80 | 81 | result.props[map][value] = result.props[map][value] || []; 82 | result.props[map][value].push(parsed.value); 83 | } 84 | }); 85 | 86 | return result; 87 | } 88 | 89 | export function bind(scope, el: angular.IRootElementService, hostBindings: any, controllerAs: string = '$ctrl') { 90 | // Handle attributes 91 | Object.keys(hostBindings.attrs).forEach(attribute => { 92 | el.attr(attribute, hostBindings.attrs[attribute]); 93 | }); 94 | 95 | // Handle host listeners 96 | Object.keys(hostBindings.events).forEach(event => { 97 | const target = hostBindings.events[event]; 98 | 99 | el.bind(event, e => { 100 | const ctx = {$event: e}; 101 | // use scope.$apply because we are outside the angular digest cycle 102 | scope.$apply(() => { 103 | scope[controllerAs][target.method].apply(scope[controllerAs], target.params.map(param => dotProp.get(ctx, param))); 104 | }); 105 | }); 106 | }); 107 | 108 | // Handle host property bindings 109 | Object.keys(hostBindings.props.raw).forEach(value => { 110 | const properties = hostBindings.props.raw[value]; 111 | applyValueToProperties(el, properties, value); 112 | }); 113 | 114 | Object.keys(hostBindings.props.expressions).forEach(expression => { 115 | const properties = hostBindings.props.expressions[expression]; 116 | scope.$watch(`${controllerAs}.${expression}`, newValue => { 117 | applyValueToProperties(el, properties, newValue); 118 | }); 119 | }); 120 | } 121 | -------------------------------------------------------------------------------- /angular2-polyfill/src/platform/utils/injector.ts: -------------------------------------------------------------------------------- 1 | declare const Reflect; 2 | 3 | /** 4 | * Creates a factory with the name `@Optional({injectable})` which checks 5 | * if the injectable exists or not. If the injectable exists, the factory 6 | * will return the injectable, if not, it will return `null`. 7 | * 8 | * @param {ng.IModule} ngModule The root module. 9 | * @param {string} injectable The name of the optional injectable. 10 | * @returns {string} The name of the factory. 11 | */ 12 | function createOptionalInject(ngModule: ng.IModule, injectable: string) { 13 | const name = `@Optional(${injectable})`; 14 | 15 | const factory = $injector => { 16 | if ($injector.has(injectable)) { 17 | return $injector.get(injectable); 18 | } 19 | 20 | return null; 21 | }; 22 | 23 | factory.$inject = ['$injector']; 24 | 25 | // Create the factory 26 | ngModule.factory(name, factory); 27 | 28 | return name; 29 | } 30 | 31 | export function inject(ngModule: ng.IModule, target) { 32 | const annotations = target.__annotations__ || {}; 33 | const injectables = []; 34 | 35 | if (annotations.inject) { 36 | annotations.inject.forEach((injectable, index) => { 37 | let name = typeof injectable === 'string' ? injectable : injectable.name; 38 | 39 | if (annotations.optional && annotations.optional[index] === true) { 40 | // If the injectable is optional, replace the name with the optional injector 41 | name = createOptionalInject(ngModule, name); 42 | } 43 | 44 | injectables[index] = name; 45 | }); 46 | } 47 | 48 | if (Reflect.hasMetadata('design:paramtypes', target)) { 49 | Reflect.getMetadata('design:paramtypes', target).forEach((type, index) => { 50 | if (type.name !== 'Object' && injectables[index] === undefined) { 51 | let name = type.name; 52 | 53 | if (annotations.optional && annotations.optional[index] === true) { 54 | // If the injectable is optional, replace the name with the optional injector 55 | name = createOptionalInject(ngModule, name); 56 | } 57 | 58 | injectables[index] = name; 59 | } 60 | }); 61 | } 62 | 63 | target.$inject = injectables; 64 | } 65 | -------------------------------------------------------------------------------- /angular2-polyfill/src/platform/utils/input.ts: -------------------------------------------------------------------------------- 1 | declare const Reflect; 2 | 3 | /** 4 | * Bind the inputs defined on the target to the directive. 5 | */ 6 | export function bind(target, directive) { 7 | const annotations = target.__annotations__; 8 | const component = annotations.component || annotations.directive; 9 | 10 | function toBinding(key, value) { 11 | const match = value.match(/^([@=<])?(.*)?$/); 12 | 13 | if (match[1]) { 14 | // signed inputs (<, @, =) 15 | return { 16 | key: match[2] || key, 17 | value: match[1] + (match[2] || key) 18 | } 19 | } 20 | 21 | let sign = '@'; 22 | 23 | if (Reflect.hasMetadata('design:type', target.prototype, key)) { 24 | // If the type is not a primitive, use pass-by-reference 25 | const type = Reflect.getMetadata('design:type', target.prototype, key); 26 | 27 | if (type.name !== 'String' && type.name !== 'Number' && type.name !== 'Boolean') { 28 | sign = '='; 29 | } 30 | } 31 | 32 | return { 33 | key: key, 34 | value: sign + value 35 | }; 36 | } 37 | 38 | // Bind all the elements in the `inputs` array 39 | (component.inputs || []).forEach(key => { 40 | const mapping = key.split(/:[ ]*/); 41 | const binding = toBinding(mapping[0], mapping[1] || mapping[0]); 42 | directive.bindToController[binding.key] = binding.value; 43 | }); 44 | 45 | // Bind all the elements in the `@Input` annotation list 46 | Object.keys(annotations.inputs || {}).forEach(key => { 47 | const binding = toBinding(key, annotations.inputs[key]); 48 | directive.bindToController[binding.key] = binding.value; 49 | }); 50 | } 51 | -------------------------------------------------------------------------------- /angular2-polyfill/src/platform/utils/output.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a property with the name of the key provided to the target 3 | * prototype. Whenever a binding with that name is set, the `set` method of 4 | * that property is called and we can hook into the internals. This way we can also 5 | * handle event emitters. 6 | */ 7 | function attachPropertyHook(scope, target, key, name) { 8 | const wrapper = `__${name}Fn`; 9 | 10 | Object.defineProperty(target.prototype, key, { 11 | enumerable: true, 12 | configurable: true, 13 | get: function () { 14 | return this[`_${name}`]; 15 | }, 16 | set: function (value) { 17 | if (this[wrapper] === undefined) { 18 | // Catch the `` setter 19 | this[wrapper] = value; 20 | return; 21 | } 22 | 23 | if (!(value && value.emit && value.subscribe)) { 24 | // Throw error if the value is not an EventEmitter 25 | throw new TypeError(`Expected '${key}' to be an 'EventEmitter', got '${typeof value}'.`); 26 | } 27 | 28 | this[`_${name}`] = value; 29 | value.subscribe(e => { 30 | scope.$apply(() => { 31 | this[wrapper]({$event: e}); 32 | }); 33 | }); 34 | } 35 | }); 36 | } 37 | 38 | export function bind(scope, target, directive) { 39 | const annotations = target.__annotations__; 40 | const component = annotations.component || annotations.directive; 41 | 42 | // Bind all the elements in the `outputs` array 43 | (component.outputs || []).forEach(key => { 44 | const mapping = key.split(/:[ ]*/); 45 | const name = mapping[1] || mapping[0]; 46 | 47 | attachPropertyHook(scope, target, key, name); 48 | directive.bindToController[mapping[0]] = `&${name}`; 49 | }); 50 | 51 | // Bind all the `@Output` annotations 52 | Object.keys(annotations.outputs || {}).forEach(key => { 53 | const name = annotations.outputs[key]; 54 | 55 | attachPropertyHook(scope, target, key, name); 56 | directive.bindToController[key] = `&${name}`; 57 | }); 58 | } 59 | -------------------------------------------------------------------------------- /angular2-polyfill/src/router-deprecated/decorators/RouteConfig.ts: -------------------------------------------------------------------------------- 1 | import {RouteDefinition} from '../interfaces'; 2 | import {annotate} from '../../utils'; 3 | 4 | export function RouteConfig(routes: RouteDefinition[]) { 5 | return (target: any) => { 6 | annotate(target, 'routes', routes); 7 | }; 8 | } 9 | -------------------------------------------------------------------------------- /angular2-polyfill/src/router-deprecated/instruction.ts: -------------------------------------------------------------------------------- 1 | import {Inject} from '../../core'; 2 | 3 | export class RouteParams { 4 | constructor(@Inject('$stateParams') private stateParams) {} 5 | 6 | get(param: string): string { 7 | return this.stateParams[param]; 8 | } 9 | } 10 | 11 | export class Instruction { 12 | _state: string; 13 | urlPath: string; 14 | urlParams: string; 15 | } 16 | -------------------------------------------------------------------------------- /angular2-polyfill/src/router-deprecated/interfaces.ts: -------------------------------------------------------------------------------- 1 | export interface RouteDefinition { 2 | path?: string, 3 | component?: any, 4 | as?: string, 5 | name?: string, 6 | useAsDefault?: boolean 7 | } 8 | -------------------------------------------------------------------------------- /angular2-polyfill/src/router-deprecated/lifecycle/lifecycle_annotations.ts: -------------------------------------------------------------------------------- 1 | import {Instruction} from '../instruction'; 2 | import {annotate} from '../../utils'; 3 | 4 | export function CanActivate(hook: Function | ((next: Instruction, prev: Instruction) => Promise | boolean)) { 5 | return (target: any) => { 6 | annotate(target, 'router.canActivate', hook); 7 | }; 8 | } 9 | 10 | export interface CanActivate { 11 | routerCanActivate(next: Instruction, prev: Instruction): Promise | boolean; 12 | } 13 | -------------------------------------------------------------------------------- /angular2-polyfill/src/router-deprecated/providers.ts: -------------------------------------------------------------------------------- 1 | import {Router} from './router'; 2 | import {RouteParams} from './instruction'; 3 | 4 | // Export the providers 5 | export const ROUTER_PROVIDERS = [Router, RouteParams]; 6 | -------------------------------------------------------------------------------- /angular2-polyfill/src/router-deprecated/router.ts: -------------------------------------------------------------------------------- 1 | import {Inject} from '../../core'; 2 | import {Instruction} from './instruction'; 3 | 4 | export class Router { 5 | 6 | constructor(@Inject('$state') private state) { 7 | 8 | } 9 | 10 | isRouteActive(instruction: Instruction): boolean { 11 | return this.state.is(instruction._state, instruction.urlParams); 12 | } 13 | 14 | navigate(linkParams: any[]): Promise { 15 | return this.state.go(linkParams[0], linkParams[1] || {}); 16 | } 17 | 18 | renavigate(): Promise { 19 | return this.state.reload(this.state.current); 20 | } 21 | 22 | generate(linkParams: any[]): Promise { 23 | const state = linkParams[0]; 24 | const params = linkParams[1] || {}; 25 | const url = this.state.href(state, params); 26 | 27 | const instruction = new Instruction(); 28 | instruction._state = state; 29 | instruction.urlPath = this.state.href(state, params); 30 | instruction.urlParams = params; 31 | 32 | return Promise.resolve(instruction); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /angular2-polyfill/src/utils.ts: -------------------------------------------------------------------------------- 1 | import * as dotProp from 'dot-prop'; 2 | import * as camelcase from 'camelcase'; 3 | import {OpaqueToken} from './core/core'; 4 | 5 | /** 6 | * Helper functions 7 | */ 8 | 9 | export function annotate(target, key, value) { 10 | if (!target.__annotations__) { 11 | target.__annotations__ = {}; 12 | } 13 | 14 | dotProp.set(target.__annotations__, key, value); 15 | } 16 | 17 | export function toInjectorName(token) { 18 | if (typeof token === 'string') { 19 | return token; 20 | } 21 | 22 | if (token instanceof OpaqueToken) { 23 | return camelcase(token.toString()); 24 | } 25 | 26 | return token.name; 27 | } 28 | -------------------------------------------------------------------------------- /angular2-polyfill/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "outDir": "./", 6 | "sourceMap": false, 7 | "declaration": true, 8 | "experimentalDecorators": true 9 | }, 10 | "exclude": [ 11 | "bundles", 12 | "node_modules", 13 | "typings/browser", 14 | "typings/browser.d.ts" 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /angular2-polyfill/tsd.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "v4", 3 | "repo": "borisyankov/DefinitelyTyped", 4 | "ref": "master", 5 | "path": "typings", 6 | "bundle": "typings/tsd.d.ts", 7 | "installed": { 8 | "dot-prop/dot-prop.d.ts": { 9 | "commit": "d1f6bde13f2209be42e86c3686761e8bfcbb50a5" 10 | }, 11 | "camelcase/camelcase.d.ts": { 12 | "commit": "d1f6bde13f2209be42e86c3686761e8bfcbb50a5" 13 | }, 14 | "angularjs/angular.d.ts": { 15 | "commit": "d1f6bde13f2209be42e86c3686761e8bfcbb50a5" 16 | }, 17 | "jquery/jquery.d.ts": { 18 | "commit": "d1f6bde13f2209be42e86c3686761e8bfcbb50a5" 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /angular2-polyfill/typings.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": {}, 3 | "ambientDependencies": { 4 | "angular": "github:DefinitelyTyped/DefinitelyTyped/angularjs/angular.d.ts#1c4a34873c9e70cce86edd0e61c559e43dfa5f75", 5 | "camelcase": "github:DefinitelyTyped/DefinitelyTyped/camelcase/camelcase.d.ts#47f676c60034918529f22b80fc5a4dab873bd189", 6 | "decamelize": "github:DefinitelyTyped/DefinitelyTyped/decamelize/decamelize.d.ts#e1bf187e0877662d58712b14c3c14fecfd4ea4cc", 7 | "dot-prop": "github:DefinitelyTyped/DefinitelyTyped/dot-prop/dot-prop.d.ts#8b515b23637d52a56741bca9a6e67d42ff0422df", 8 | "es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#4de74cb527395c13ba20b438c3a7a419ad931f1c", 9 | "jquery": "github:DefinitelyTyped/DefinitelyTyped/jquery/jquery.d.ts#470954c4f427e0805a2d633636a7c6aa7170def8" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const path = require('path'); 3 | const gulp = require('gulp'); 4 | const Builder = require('systemjs-builder'); 5 | const jeditor = require('gulp-json-editor'); 6 | const pkg = require('./package.json'); 7 | 8 | const ANGULAR2_POLYFILL_BUNDLE_CONFIG = [ 9 | 'angular2-polyfill/core', 10 | 'angular2-polyfill/http', 11 | 'angular2-polyfill/router-deprecated', 12 | 'angular2-polyfill/platform/upgrade' 13 | ]; 14 | 15 | const NG2_POLYFILL_BUNDLE_CONTENT = ANGULAR2_POLYFILL_BUNDLE_CONFIG.join(' + '); 16 | 17 | const BASE = path.join(__dirname, 'angular2-polyfill'); 18 | 19 | const bundleConfig = { 20 | map: { 21 | 'dot-prop': path.join(BASE, '/node_modules/dot-prop/index.js'), 22 | 'is-obj': path.join(BASE, '/node_modules/is-obj/index.js'), 23 | 'camelcase': path.join(BASE, '/node_modules/camelcase/index.js'), 24 | 'decamelize': path.join(BASE, '/node_modules/decamelize/index.js'), 25 | 'rxjs': path.join(BASE, '/node_modules/rxjs/Rx.js') 26 | }, 27 | meta: { 28 | rxjs: { 29 | build: false 30 | } 31 | }, 32 | paths: { 33 | '*': '*.js' 34 | } 35 | }; 36 | 37 | function bundle(buildConfig, moduleName, outputFile, outputConfig) { 38 | const builder = new Builder(); 39 | builder.config(buildConfig); 40 | return builder.bundle(moduleName, outputFile, outputConfig); 41 | } 42 | 43 | gulp.task('bundle', () => { 44 | return bundle(bundleConfig, NG2_POLYFILL_BUNDLE_CONTENT, './angular2-polyfill/bundles/angular2-polyfill.js', {sourceMaps: true}); 45 | }); 46 | 47 | gulp.task('version', () => { 48 | const cwd = 'angular2-polyfill'; 49 | 50 | return gulp.src('package.json', {cwd}) 51 | .pipe(jeditor({version: pkg.version})) 52 | .pipe(gulp.dest('.', {cwd})); 53 | }); 54 | 55 | gulp.task('readme', () => { 56 | return gulp.src('readme.md') 57 | .pipe(gulp.dest('angular2-polyfill')); 58 | }); 59 | 60 | gulp.task('build', ['bundle', 'version', 'readme']); 61 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Sam Verschueren (github.com/SamVerschueren) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular2-polyfill", 3 | "version": "0.0.32", 4 | "description": "Angular2 polyfill for Angular1", 5 | "license": "MIT", 6 | "repository": "SamVerschueren/angular2-polyfill", 7 | "private": true, 8 | "author": { 9 | "name": "Sam Verschueren", 10 | "email": "sam.verschueren@gmail.com", 11 | "url": "github.com/SamVerschueren" 12 | }, 13 | "scripts": { 14 | "test": "npm run compile && ava", 15 | "postinstall": "npm run typings install && cd angular2-polyfill && npm install", 16 | "build": "npm run compile && npm run tsd-gen && gulp build", 17 | "compile": "tsc -p ./angular2-polyfill", 18 | "watch": "tsc -watch -p ./angular2-polyfill", 19 | "pub": "cd angular2-polyfill && npm publish", 20 | "typings": "cd angular2-polyfill && typings", 21 | "link": "cd angular2-polyfill && jspm link npm:angular2-polyfill@dev -y", 22 | "tsd-gen": "tsc -p angular2-polyfill --outFile angular2-polyfill/bundles/angular2-polyfill.js --module system -d --moduleResolution node --rootDir \"./\"" 23 | }, 24 | "devDependencies": { 25 | "ava": "*", 26 | "gulp": "^3.9.1", 27 | "gulp-json-editor": "^2.2.1", 28 | "jspm": "^0.16.34", 29 | "sinon": "^1.17.3", 30 | "systemjs-builder": "^0.15.12", 31 | "typescript": "^1.8.7", 32 | "typings": "^0.7.9" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # angular2-polyfill 2 | 3 | [![Build Status](https://travis-ci.org/SamVerschueren/angular2-polyfill.svg?branch=master)](https://travis-ci.org/SamVerschueren/angular2-polyfill) 4 | [![CDNJS](https://img.shields.io/cdnjs/v/angular2-polyfill.svg)](https://cdnjs.com/libraries/angular2-polyfill) 5 | 6 | > Angular2 polyfill for Angular1 7 | 8 | **Please note, this is a work in progress library** 9 | 10 | 11 | ## Install 12 | 13 | ``` 14 | $ npm install --save angular2-polyfill 15 | ``` 16 | 17 | Or with `jspm` 18 | 19 | ``` 20 | $ jspm install npm:angular2-polyfill 21 | ``` 22 | 23 | 24 | ## Usage 25 | 26 | ### AppComponent 27 | 28 | The `AppComponent` is the base component for our entire application. The following content is stored in `components/app/app.component.ts`. Because 29 | we are using `ui-router`, the only thing we add as a template is the place where the views should be rendered. 30 | 31 | ```ts 32 | import {Component} from 'angular2-polyfill/core'; 33 | import {RouteConfig} from 'angular2-polyfill/router-deprecated'; 34 | import {HomeComponent} from '../home/home.component'; 35 | 36 | @Component({ 37 | selector: 'my-app', 38 | template: '
' 39 | }) 40 | @RouteConfig([ 41 | { path: '/', component: HomeComponent, name: 'Home', useAsDefault: true } 42 | ]) 43 | export class AppComponent { 44 | 45 | } 46 | ``` 47 | 48 | ### HomeComponent 49 | 50 | The `HomeComponent` simply renders the title defined in the class. Please note that in the background, we use the `controllerAs` syntax. The value of this property 51 | is consistent with the Angular 1.5 [component](https://docs.angularjs.org/guide/component) value. The following content is stored in `components/home/home.component.ts`. 52 | 53 | ```ts 54 | import {Component} from 'angular2-polyfill/core' 55 | 56 | @Component({ 57 | selector: 'home', 58 | template: '

{{ $ctrl.title }}

', 59 | styles: [` 60 | h1 { 61 | color: red; 62 | } 63 | `] 64 | }) 65 | export class HomeComponent { 66 | private title: string = 'Hello World'; 67 | } 68 | ``` 69 | 70 | ### Bootstrapping 71 | 72 | Use the `bootstrap` method from the `upgrade` platform. This allows you to rewrite your entire application at your own 73 | pace. It accepts the base angular module as first argument, and the component/service/... as second argument. This way, you can 74 | keep the other component as they are now and refactor them in the future. 75 | 76 | ```ts 77 | import * as angular from 'angular'; 78 | import 'angular-ui-router'; 79 | import 'reflect-metadata'; 80 | import {bootstrap} from 'angular2-polyfill/platform/upgrade'; 81 | import {AppComponent} from './components/app/app.component'; 82 | 83 | const ngModule = angular.module('angular2-polyfill', ['ui.router']); 84 | 85 | bootstrap(ngModule, AppComponent); 86 | ``` 87 | 88 | > Note: The `HomeComponent` is being bootstrapped automatically because it is referred to in the `@RouteConfig` decorator of the `AppComponent`. 89 | 90 | ### index.html 91 | 92 | ```html 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 106 | 107 | 108 | ``` 109 | 110 | We are using SystemJS as module loader. Feel free to use something else. 111 | 112 | 113 | ## Decorators 114 | 115 | - @Component 116 | - @Directive 117 | - @RouteConfig 118 | - @Injectable 119 | - @Inject 120 | - @Optional 121 | - @Pipe 122 | 123 | 124 | ## Pipes 125 | 126 | - AsyncPipe 127 | 128 | 129 | ## Services 130 | 131 | ### Core 132 | 133 | - EventEmitter 134 | 135 | ### DI 136 | 137 | - Injector 138 | 139 | ### HTTP 140 | 141 | - Http 142 | 143 | ### Routing 144 | 145 | - Router 146 | - RouteParams 147 | 148 | 149 | ## Functions 150 | 151 | - provide 152 | 153 | 154 | ## Lifecycle hooks 155 | 156 | - ngOnInit 157 | - ngOnDestroy 158 | 159 | 160 | ## Examples 161 | 162 | ### GitHub 163 | 164 | - [Tour of Heroes](https://github.com/SamVerschueren/angular2-polyfill-heroes) - Tour of Heroes implementation 165 | 166 | ### Plunks 167 | 168 | - [Tour of Heroes](https://plnkr.co/edit/tV8gO6cPCJlcu49qAwoN) - Tour of Heroes 169 | - [Routing](http://plnkr.co/edit/AdhtnTfA8pnAeFRk2qDE) - Routing example 170 | 171 | 172 | ## License 173 | 174 | MIT © [Sam Verschueren](https://github.com/SamVerschueren) 175 | -------------------------------------------------------------------------------- /test/core/classes/opaque_token.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import {OpaqueToken} from '../../../angular2-polyfill/src/core/classes/opaque_token'; 3 | 4 | test(t => { 5 | t.not(new OpaqueToken('foo').toString(), new OpaqueToken('foo').toString()); 6 | }); 7 | -------------------------------------------------------------------------------- /test/platform/utils/fixtures/reflect.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | exports.Reflect = global.Reflect = { 3 | hasMetadata: () => false, 4 | getMetadata: () => String 5 | }; 6 | -------------------------------------------------------------------------------- /test/platform/utils/fixtures/scope.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | class Scope { 3 | 4 | $apply(cb) { 5 | cb(); 6 | } 7 | } 8 | 9 | exports.Scope = Scope; 10 | -------------------------------------------------------------------------------- /test/platform/utils/fixtures/utils.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | class Target { 4 | 5 | constructor() { 6 | 7 | } 8 | } 9 | 10 | const createTarget = (type, v) => { 11 | Target.__annotations__ = {component: {}}; 12 | 13 | if (Array.isArray(v)) { 14 | Target.__annotations__.component[type] = v; 15 | } else { 16 | Target.__annotations__[type] = v; 17 | } 18 | 19 | return Target; 20 | }; 21 | 22 | exports.output = function (scope, outputs) { 23 | const target = createTarget('outputs', outputs); 24 | const directive = {bindToController: {}}; 25 | 26 | this(scope, target, directive); 27 | 28 | return { 29 | target, 30 | bindings: directive.bindToController 31 | }; 32 | } 33 | 34 | exports.input = function (inputs) { 35 | const target = createTarget('inputs', inputs); 36 | const directive = {bindToController: {}}; 37 | 38 | this(target, directive); 39 | 40 | return directive.bindToController; 41 | }; 42 | -------------------------------------------------------------------------------- /test/platform/utils/host-parsing.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import {parse as m} from '../../../angular2-polyfill/src/platform/utils/host'; 3 | 4 | const attrs = {}; 5 | const events = {}; 6 | const props = {raw: {}, expressions: {}}; 7 | 8 | test('attributes', t => { 9 | t.deepEqual(m({foo: 'bar'}), { 10 | attrs: { 11 | foo: 'bar' 12 | }, 13 | events, 14 | props 15 | }); 16 | 17 | t.deepEqual(m({foo: 'bar', hello: 'world'}), { 18 | attrs: { 19 | foo: 'bar', 20 | hello: 'world' 21 | }, 22 | events, 23 | props 24 | }); 25 | }); 26 | 27 | test('event', t => { 28 | t.deepEqual(m({ '(click)': 'onClick()' }), { 29 | events: { 30 | click: { 31 | method: 'onClick', 32 | params: [] 33 | } 34 | }, 35 | attrs, 36 | props 37 | }); 38 | }); 39 | 40 | test('event with `$event` object', t => { 41 | t.deepEqual(m({ '(mouseleave)': 'onMouseLeave($event)' }), { 42 | events: { 43 | mouseleave: { 44 | method: 'onMouseLeave', 45 | params: ['$event'] 46 | } 47 | }, 48 | attrs, 49 | props 50 | }); 51 | }); 52 | 53 | test('event with multiple params', t => { 54 | t.deepEqual(m({ '(mouseenter)': 'onMouseEnter($event, foo, bar,baz)' }), { 55 | events: { 56 | mouseenter: { 57 | method: 'onMouseEnter', 58 | params: ['$event', 'foo', 'bar', 'baz'] 59 | } 60 | }, 61 | attrs, 62 | props 63 | }); 64 | }); 65 | 66 | test('properties', t => { 67 | t.deepEqual(m({'[foo]': 'bar'}), { 68 | attrs, 69 | events, 70 | props: { 71 | raw: {}, 72 | expressions: { 73 | bar: ['foo'] 74 | } 75 | } 76 | }); 77 | }); 78 | 79 | test('multiple properties', t => { 80 | t.deepEqual(m({'[foo]': 'bar', '[class.red]': 'red', '[style.background]': 'red'}), { 81 | attrs, 82 | events, 83 | props: { 84 | raw: {}, 85 | expressions: { 86 | bar: ['foo'], 87 | red: ['class.red', 'style.background'] 88 | } 89 | } 90 | }); 91 | }); 92 | 93 | test('raw properties', t => { 94 | t.deepEqual(m({'[hello]': '"world"'}), { 95 | attrs, 96 | events, 97 | props: { 98 | raw: { 99 | world: ['hello'] 100 | }, 101 | expressions: {} 102 | } 103 | }); 104 | }); 105 | 106 | test('multiple raw properties', t => { 107 | t.deepEqual(m({'[hello]': '"world"', '[style.background]': '"red"'}), { 108 | attrs, 109 | events, 110 | props: { 111 | raw: { 112 | world: ['hello'], 113 | red: ['style.background'] 114 | }, 115 | expressions: {} 116 | } 117 | }); 118 | }); 119 | -------------------------------------------------------------------------------- /test/platform/utils/input-binding.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import sinon from 'sinon'; 3 | import {Reflect} from './fixtures/reflect'; 4 | import utils from './fixtures/utils'; 5 | import {bind as m} from '../../../angular2-polyfill/src/platform/utils/input'; 6 | 7 | const sandbox = sinon.sandbox.create(); 8 | const bind = utils.input.bind(m); 9 | 10 | test.before(() => { 11 | const has = sandbox.stub(Reflect, 'hasMetadata'); 12 | has.withArgs('design:type', sinon.match.any, 'hello').returns(true); 13 | has.withArgs('design:type', sinon.match.any, 'world').returns(true); 14 | 15 | const get = sandbox.stub(Reflect, 'getMetadata'); 16 | get.withArgs('design:type', sinon.match.any, 'hello').returns(String); 17 | get.withArgs('design:type', sinon.match.any, 'world').returns(Object); 18 | }); 19 | 20 | test.after(() => { 21 | sandbox.restore(); 22 | }); 23 | 24 | test('inputs array', t => { 25 | t.deepEqual(bind(['foo']), {foo: '@foo'}); 26 | t.deepEqual(bind(['foo', 'bar', 'baz']), {foo: '@foo', bar: '@bar', baz: '@baz'}); 27 | }); 28 | 29 | test('mapped inputs array', t => { 30 | t.deepEqual(bind(['foo:bar']), {foo: '@bar'}); 31 | t.deepEqual(bind(['foo:bar', 'bar: baz']), {foo: '@bar', bar: '@baz'}); 32 | }); 33 | 34 | test('signed inputs array', t => { 35 | t.deepEqual(bind(['=foo']), {foo: '=foo'}); 36 | }); 37 | 38 | test('inputs annotation', t => { 39 | t.deepEqual(bind({hello: 'hello'}), {hello: '@hello'}); 40 | t.deepEqual(bind({world: 'world'}), {world: '=world'}); 41 | }); 42 | 43 | test('mapped inputs annotation', t => { 44 | t.deepEqual(bind({hello: 'world'}), {hello: '@world'}); 45 | t.deepEqual(bind({world: 'hello'}), {world: '=hello'}); 46 | }); 47 | 48 | test('signed inputs annotation', t => { 49 | t.deepEqual(bind({hello: '<'}), {hello: ' bind(t.context.scope, ...args).bindings; 10 | const target = (t, ...args) => bind(t.context.scope, ...args).target; 11 | 12 | test.beforeEach(t => { 13 | const scope = new Scope(); 14 | sinon.spy(scope, '$apply'); 15 | t.context.scope = scope; 16 | }); 17 | 18 | test('outputs array', t => { 19 | t.deepEqual(bindings(t, ['foo']), {foo: '&foo'}); 20 | t.deepEqual(bindings(t, ['foo', 'bar', 'baz']), {foo: '&foo', bar: '&bar', baz: '&baz'}); 21 | }); 22 | 23 | test('mapped outputs array', t => { 24 | t.deepEqual(bindings(t, ['foo:bar']), {foo: '&bar'}); 25 | t.deepEqual(bindings(t, ['foo:bar', 'bar: baz']), {foo: '&bar', bar: '&baz'}); 26 | }); 27 | 28 | test('outputs annotation', t => { 29 | t.deepEqual(bindings(t, {foo: 'foo'}), {foo: '&foo'}); 30 | t.deepEqual(bindings(t, {foo: 'foo', bar: 'bar', baz: 'baz'}), {foo: '&foo', bar: '&bar', baz: '&baz'}); 31 | }); 32 | 33 | test('mapped outputs annotation', t => { 34 | t.deepEqual(bindings(t, {hello: 'world'}), {hello: '&world'}); 35 | t.deepEqual(bindings(t, {world: 'hello'}), {world: '&hello'}); 36 | }); 37 | 38 | test('has property hook', t => { 39 | t.true(target(t, ['foo']).prototype.hasOwnProperty('foo')); 40 | }); 41 | 42 | test('property hook function throws error', t => { 43 | const Target = target(t, ['foo']); 44 | const instance = new Target(); 45 | instance.foo = () => { }; 46 | 47 | t.throws(() => { 48 | instance.foo = () => 'bar'; 49 | }, `Expected 'foo' to be an 'EventEmitter', got 'function'.`); 50 | }); 51 | 52 | test.cb('property hook EventEmitter', t => { 53 | const Target = target(t, ['foo']); 54 | const instance = new Target(); 55 | 56 | // First set the listener function 57 | // This mimics the `` setter 58 | instance.foo = ({$event}) => { 59 | t.is($event, 'bar'); 60 | t.true(t.context.scope.$apply.calledOnce); 61 | t.end(); 62 | }; 63 | 64 | // Then set the EventEmitter 65 | // This mimics the `@Output() foo = new EventEmitter()` setter 66 | instance.foo = new EventEmitter(); 67 | instance.foo.emit('bar'); 68 | }); 69 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "outDir": "./angular2-polyfill", 6 | "sourceMap": false, 7 | "declaration": true, 8 | "experimentalDecorators": true 9 | }, 10 | "exclude": [ 11 | "node_modules", 12 | "angular2-polyfill/typings/browser", 13 | "angular2-polyfill/typings/browser.d.ts" 14 | ] 15 | } 16 | --------------------------------------------------------------------------------