Skip to content

Commit

Permalink
feat(*): switch to UMD bundle (from SystemJS)
Browse files Browse the repository at this point in the history
chore(*): Added types
chore(*): Update to angular2 rc.4
  • Loading branch information
christopherthielen committed Jul 9, 2016
1 parent e4e035d commit 9fef214
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<a name="1.0.7"></a>
# 1.0.7 (2016-06-30)
# 1.0.7 (2016-07-09)

update for ng2 rc.3 and ui-router 1.0.0-beta.1
update for ng2 rc.4 and ui-router 1.0.0-beta.1

<a name="1.0.6"></a>
# 1.0.6 (2016-05-12)
Expand Down
31 changes: 18 additions & 13 deletions ng1-to-ng2.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import * as angular from "angular";
import {provide, ElementRef, Component, Inject, ComponentMetadata} from "@angular/core";
import {UpgradeAdapter} from "@angular/upgrade";

import { Ng1ViewConfig, StateProvider, State } from "angular-ui-router";

import {
UIView, UIRouter, TransitionService, StateService, Globals, UIROUTER_DIRECTIVES, forEach, extend,
UrlRouter, ViewService, StateRegistry, UrlMatcherFactory, Ng2ViewDeclaration, Ng2ViewConfig, PathNode
UIView, UIRouter, TransitionService, StateService, Globals, UIROUTER_DIRECTIVES, forEach,
UrlRouter, ViewService, StateRegistry, UrlMatcherFactory, Ng2ViewDeclaration, Ng2ViewConfig, PathNode,
ParentUIViewInject, ViewConfig
} from "ui-router-ng2";
import {Ng1ViewConfig} from "angular-ui-router";

export let upgradeModule = angular.module('ui.router.upgrade', ['ui.router']);

declare var Reflect: any;

@Component({
selector: 'ui-view-ng-upgrade',
template: `<ui-view></ui-view>`,
Expand All @@ -22,7 +27,7 @@ export let upgradeModule = angular.module('ui.router.upgrade', ['ui.router']);
* up the DOM and grabbing the .data('$uiView') that the ng1 ui-view directive provided.
*/
class UIViewNgUpgrade {
constructor(ref: ElementRef, @Inject(UIView.PARENT_INJECT) parent, registry: StateRegistry) {
constructor(ref: ElementRef, @Inject(UIView.PARENT_INJECT) parent: ParentUIViewInject, registry: StateRegistry) {
// From the ui-view-ng-upgrade component's element ref, walk up the DOM two elements...
// There will first be one ng1 ui-view which hosts this element, and then that ui-view's
// parent element. This element has access to the proper "parent viewcontext"
Expand Down Expand Up @@ -73,14 +78,14 @@ export let uiRouterNgUpgrade = {
/**
* Predicate that returns true if an object is a NG2 Component Class
*/
export function isNg2ComponentClass(def) {
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 => x instanceof ComponentMetadata);
.find((x: any) => x instanceof ComponentMetadata);
}

/**
Expand All @@ -90,11 +95,11 @@ export function isNg2ComponentClass(def) {
* In place of the template provider, it simply puts a <ui-view-ng-upgrade/> component, which is the
* downgraded Ng2 Component that provides a ng1-to-ng2 boundary in the DOM.
*/
upgradeModule.config([ '$stateProvider', $stateProvider => {
$stateProvider.decorator('views', function(state /*: Ng1StateDeclaration */, parentFn: Function) {
upgradeModule.config([ '$stateProvider', ($stateProvider: StateProvider) => {
$stateProvider.decorator('views', function(state: State, parentFn: Function) {
let views = parentFn(state);

forEach(views, (viewDecl /*: Ng1ViewDeclaration */, viewName: string) => {
forEach(views, (viewDecl: any, viewName: string) => {
if (isNg2ComponentClass(viewDecl.component)) {
// Update the view config.
// Override default ng1 `component:` behavior (of defining a templateProvider)
Expand All @@ -108,12 +113,12 @@ upgradeModule.config([ '$stateProvider', $stateProvider => {
})
}]);

upgradeModule.run([ '$view', $view => {
upgradeModule.run([ '$view', ($view: ViewService) => {
$view.viewConfigFactory('ng2', (path: PathNode[], config: Ng2ViewDeclaration) => new Ng2ViewConfig(path, config));

$view.viewConfigFactory('ng1-to-ng2', (node: PathNode, config: Ng2ViewDeclaration) => {
var ng1ViewConfig = new Ng1ViewConfig(<any> node, <any> Object.assign({}, config, { $type: 'ng1'}));
var ng2ViewConfig = new Ng2ViewConfig(<any> node, <any> Object.assign({}, config, { $type: 'ng2'}));
$view.viewConfigFactory('ng1-to-ng2', (path: PathNode[], config: Ng2ViewDeclaration) => {
var ng1ViewConfig: ViewConfig = <any> new Ng1ViewConfig(<any> path, <any> Object.assign({}, config, { $type: 'ng1'}));
var ng2ViewConfig: ViewConfig = <any> new Ng2ViewConfig(<any> path, <any> Object.assign({}, config, { $type: 'ng2'}));

return [ ng2ViewConfig, ng1ViewConfig ];
});
Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,25 @@
"license": "MIT",
"peerDependencies": {
"angular": "^1.5.0",
"@angular/core": "^2.0.0-rc.3",
"@angular/upgrade": "^2.0.0-rc.3",
"@angular/core": "^2.0.0-rc.4",
"@angular/upgrade": "^2.0.0-rc.4",
"rxjs": "=5.0.0-beta.6",
"angular-ui-router": "^1.0.0-beta.1",
"ui-router-ng2": "^1.0.0-beta.1"
},
"devDependencies": {
"@angular/common": "^2.0.0-rc.3",
"@angular/compiler": ">=2.0.0-rc.3",
"@angular/core": ">=2.0.0-rc.3",
"@angular/platform-browser": ">=2.0.0-rc.3",
"@angular/upgrade": ">=2.0.0-rc.3",
"@angular/common": "^2.0.0-rc.4",
"@angular/compiler": ">=2.0.0-rc.4",
"@angular/core": ">=2.0.0-rc.4",
"@angular/platform-browser": ">=2.0.0-rc.4",
"@angular/upgrade": ">=2.0.0-rc.4",
"angular": "1.5.3",
"angular-ui-router": ">=1.0.0-beta.1",
"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.6",
"systemjs": "0.19.25",
"typescript": "^1.8.9",
"typings": "^0.7.11",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "es5",
"module": "system",
"module": "umd",
"moduleResolution": "node",
"sourceMap": true,
"declaration": true,
Expand Down

0 comments on commit 9fef214

Please sign in to comment.