Skip to content

Commit

Permalink
Merge pull request #15 from swimlane/master
Browse files Browse the repository at this point in the history
Angular2 Final Fixes
  • Loading branch information
christopherthielen authored Sep 21, 2016
2 parents 391bee6 + 01bcb6a commit 5cb5e11
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 5,853 deletions.
37 changes: 16 additions & 21 deletions ng1-to-ng2.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import * as angular from "angular";
import {Ng1ViewConfig, $InjectorLike} from "angular-ui-router";

import {ElementRef, Component, Input, Inject, ComponentMetadata, NgModule} from "@angular/core";
import {ElementRef, Component, Input, Inject, NgModule} from "@angular/core";
import {UpgradeAdapter} from "@angular/upgrade";

import {
UIRouter, ViewService, StateRegistry, StateProvider,
UIView, Ng2ViewDeclaration, Ng2ViewConfig, State, PathNode, Resolvable,
ParentUIViewInject, ViewConfig, forEach, UIRouterRx,
NG2_INJECTOR_TOKEN, ngModuleResolvablesBuilder, UIRouterLibraryModule
UIRouter, ViewService, StateRegistry, StateProvider,
UIView, Ng2ViewDeclaration, Ng2ViewConfig, State, PathNode, Resolvable,
ParentUIViewInject, ViewConfig, forEach, UIRouterRx,
NG2_INJECTOR_TOKEN, ngModuleResolvablesBuilder, UIRouterLibraryModule
} from "ui-router-ng2";

declare var Reflect: any;

/**
* Create a ng1 module for the ng1 half of the hybrid application to depend on.
*
Expand All @@ -24,28 +22,28 @@ export let upgradeModule = angular.module('ui.router.upgrade', ['ui.router']);
/**
* UIViewNgUpgrade is a component bridge from ng1 ui-view to ng2 ui-view
*
* When a ui-router for ng1 is registering a state it checks if a view's
* `component:` is an ng2 Component class. If so, it creates a special ng1 template
* When a ui-router for ng1 is registering a state it checks if a view's
* `component:` is an ng2 Component class. If so, it creates a special ng1 template
* which references this component, i.e., <ui-view-ng-upgrade></ui-view-ng-upgrade>
*
* See that code by searching ng1-to-ng2 source for: "$stateProvider.decorator"
*
* ---
*
* ng1-to-ng2 component bridge process:
*
*
* 1)
* When an ng1 template creates a ui-view which is targeted by a ng2 Component,
*
*
* ```
* <a ui-sref="foo">Go to foo</a>
* <div ui-view> <!-- ui-view created in ng1 template -->
* </div> <!-- targeted with { component: Ng2RoutedComponent } -->
* ```
*
* the state decorator spits out a custom template. That template loads this
*
* the state decorator spits out a custom template. That template loads this
* ng2 Component adapter as a downgraded-to-ng1 directive.
*
*
* ```
* <a ui-sref="foo">Go to foo</a>
* <div ui-view> <!-- decorated template references the downgraded component -->
Expand All @@ -55,7 +53,7 @@ export let upgradeModule = angular.module('ui.router.upgrade', ['ui.router']);
* ```
*
* This downgraded ng2 Component then creates a child UIView (ng2 component)
*
*
* ```
* <a ui-sref="foo">Go to foo</a>
* <div ui-view> <!-- custom template references the downgraded component -->
Expand All @@ -65,9 +63,9 @@ export let upgradeModule = angular.module('ui.router.upgrade', ['ui.router']);
* </ui-view-ng-upgrade>
* </div>
* ```
*
*
* which in turn is filled with the routed ng2 component.
*
*
* ```
* <a ui-sref="foo">Go to foo</a>
* <div ui-view> <!-- ng1 ui-view -->
Expand Down Expand Up @@ -237,11 +235,8 @@ function applyHybridAdapter(upgradeAdapter: UpgradeAdapter) {
export function isNg2ComponentClass(def: any) {
if (typeof def !== 'function') return false;

if (!Reflect || typeof Reflect['metadata'] !== 'function')
throw new Error("Missing runtime dependency: 'reflect-metadata'");

return Reflect['getMetadata']('annotations', def)
.find((x: any) => x instanceof ComponentMetadata);
.find((x: any) => x instanceof Component);
}


Expand Down
40 changes: 20 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,33 @@
"license": "MIT",
"peerDependencies": {
"angular": "^1.5.0",
"@angular/core": "=2.0.0-rc.5",
"@angular/upgrade": "=2.0.0-rc.5",
"rxjs": "=5.0.0-beta.6",
"@angular/core": "~2.0.0",
"@angular/upgrade": "~2.0.0",
"core-js": "^2.4.1",
"rxjs": "~5.0.0-beta.12",
"angular-ui-router": "^1.0.0-beta.2",
"ui-router-ng2": "^1.0.0-beta.2"
"ui-router-ng2": "^1.0.0-beta.2",
"zone.js": "~0.6.21"
},
"devDependencies": {
"@angular/common": "=2.0.0-rc.5",
"@angular/compiler": "=2.0.0-rc.5",
"@angular/core": "=2.0.0-rc.5",
"@angular/platform-browser": "=2.0.0-rc.5",
"@angular/platform-browser-dynamic": "=2.0.0-rc.5",
"@angular/upgrade": "=2.0.0-rc.5",
"angular": "1.5.3",
"@angular/common": "~2.0.0",
"@angular/compiler": "~2.0.0",
"@angular/core": "~2.0.0",
"@angular/platform-browser": "~2.0.0",
"@angular/platform-browser-dynamic": "~2.0.0",
"@angular/upgrade": "~2.0.0",
"@types/angular": "^1.5.14",
"@types/core-js": "^0.9.28",
"@types/jquery": "^1.10.31",
"@types/node": "^6.0.31",
"angular": "~1.5.3",
"angular-ui-router": "^1.0.0-beta.2",
"concurrently": "^2.0.0",
"es6-shim": "^0.35.0",
"lite-server": "^2.1.0",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.6",
"rxjs": "~5.0.0-beta.12",
"systemjs": "0.19.25",
"ts-loader": "^0.8.2",
"typescript": "^1.8.9",
"typings": "^0.7.11",
"typescript": "^2.0.2",
"ui-router-ng2": "^1.0.0-beta.2",
"webpack": "^1.13.1",
"zone.js": "0.6.6"
"zone.js": "~0.6.21"
},
"main": "ng1-to-ng2.min.js",
"typings": "ng1-to-ng2.d.ts",
Expand Down
18 changes: 16 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,25 @@
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"pretty": true,
"declaration": true,
"allowSyntheticDefaultImports": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true
"noImplicitAny": false,
"suppressExcessPropertyErrors": true,
"suppressImplicitAnyIndexErrors": true,
"types": [
"core-js",
"node",
"jquery",
"angular"
]
},
"include": [ "ng1-to-ng2.ts" ]
"exclude": [
"node_modules"
],
"compileOnSave": false,
"buildOnSave": false
}
Loading

0 comments on commit 5cb5e11

Please sign in to comment.