Skip to content

Commit

Permalink
Merge branch 'master' into aot
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherthielen authored Jan 11, 2017
2 parents 271ded8 + 0a997a9 commit 75cc29b
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 61 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"clean": "shx rm -rf lib lib-esm _bundles _doc",
"build": "npm run clean && node_modules/.bin/ngc && node_modules/.bin/ngc -p tsconfig.esm.json && webpack",
"test": "karma start config/karma.ng2.js",
"docs": "typedoc --tsconfig tsconfig.typedoc.json --readme README.md --name 'ui-router-ng2' --theme node_modules/ui-router-typedoc-themes/bin/default --out _doc --external-aliases internalapi,external --navigation-label-globals ui-router-ng2"
"docs": "typedoc --tsconfig tsconfig.typedoc.json --readme README.md --name 'ui-router-ng2' --theme node_modules/ui-router-typedoc-themes/bin/default --out _doc --internal-aliases internal,coreapi,ng2api --external-aliases internalapi,external --navigation-label-globals ui-router-ng2"
},
"homepage": "https://ui-router.github.io/ng2",
"contributors": [
Expand Down Expand Up @@ -52,8 +52,8 @@
"ui-router-core": "=1.0.1"
},
"peerDependencies": {
"@angular/core": "~2.0.0",
"@angular/common": "~2.0.0"
"@angular/core": "^2.0.0",
"@angular/common": "^2.0.0"
},
"devDependencies": {
"@angular/common": "^2.3.1",
Expand Down
11 changes: 9 additions & 2 deletions src/ng2.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
/** @module ng2 */ /** for typedoc */
/** @ng2api @module ng2 */ /** for typedoc */
export * from "ui-router-core";
import "ui-router-core/lib/justjs";

import 'rxjs/add/observable/of';
import 'rxjs/add/observable/combineLatest';
import 'rxjs/add/observable/fromPromise';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/mergeMap';
import 'rxjs/add/operator/concat';
import 'rxjs/add/operator/map';

export * from "./ng2/interface";
export * from "./ng2/lazyLoadNgModule";
export * from "./ng2/rx";
Expand All @@ -11,4 +19,3 @@ export * from "./ng2/directives/directives";
export * from "./ng2/statebuilders/views";
export * from "./ng2/uiRouterNgModule";
export * from "./ng2/uiRouterConfig";

4 changes: 3 additions & 1 deletion src/ng2/directives/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* - [[UISref]]: A state ref to a target state; navigates when clicked
* - [[UISrefActive]]: (and `UISrefActiveEq`) Adds a css class when a UISref's target state (or a child state) is active
*
* @preferred @module directives
* @ng2api
* @preferred
* @module directives
*/ /** */
import {UISref, AnchorUISref} from "./uiSref";
import {UISrefActive} from "./uiSrefActive";
Expand Down
11 changes: 6 additions & 5 deletions src/ng2/directives/uiSref.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @module directives */ /** */
/** @ng2api @module directives */ /** */
import {UIRouter, UIRouterGlobals} from "ui-router-core";
import {Directive, Inject, Input} from "@angular/core";
import {Optional} from "@angular/core";
Expand All @@ -8,7 +8,8 @@ import {UIView, ParentUIViewInject} from "./uiView";
import {extend, Obj} from "ui-router-core";
import {TransitionOptions} from "ui-router-core";
import {Globals} from "ui-router-core";
import {Subscription, ReplaySubject} from "rxjs/Rx";
import {ReplaySubject} from 'rxjs/ReplaySubject';
import {Subscription} from 'rxjs/Subscription';
import {TargetState} from "ui-router-core";
import "../rx";

Expand All @@ -30,17 +31,17 @@ export class AnchorUISref {
* ### Purpose
*
* This directive is applied to anchor tags (`<a>`) or any other clickable element. It is a state reference (or sref --
* similar to an href). When clicked, the directive will transition to that state by calling [[StateService.go]],
* similar to an href). When clicked, the directive will transition to that state by calling [[StateService.go]],
* and optionally supply state parameter values and transition options.
*
* When this directive is on an anchor tag, it will also add an `href` attribute to the anchor.
*
* ### Selector
*
* - `[uiSref]`: The directive is created as an attribute on an element, e.g., `<a uiSref></a>`
*
*
* ### Inputs
*
*
* - `uiSref`: the target state's name, e.g., `uiSref="foostate"`. If a component template uses a relative `uiSref`,
* e.g., `uiSref=".child"`, the reference is relative to that component's state.
*
Expand Down
4 changes: 2 additions & 2 deletions src/ng2/directives/uiSrefActive.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @module directives */ /** */
/** @ng2api @module directives */ /** */
import {Directive, Input, ElementRef, Host, Renderer} from "@angular/core";
import {UISrefStatus, SrefStatus} from "./uiSrefStatus";
import {Subscription} from "rxjs/Rx";
import {Subscription} from "rxjs/Subscription";

/**
* A directive that adds a CSS class when its associated `uiSref` link is active.
Expand Down
6 changes: 4 additions & 2 deletions src/ng2/directives/uiSrefStatus.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @module directives */ /** */
/** @ng2api @module directives */ /** */
import {Directive, Output, EventEmitter, ContentChildren, QueryList, Inject} from "@angular/core";
import {UISref} from "./uiSref";
import {PathNode} from "ui-router-core";
Expand All @@ -9,7 +9,9 @@ import {anyTrueR, tail, unnestR, Predicate} from "ui-router-core";
import {Globals, UIRouterGlobals} from "ui-router-core";
import {Param} from "ui-router-core";
import {PathFactory} from "ui-router-core";
import {Subscription, Observable, BehaviorSubject} from "rxjs/Rx";
import {Subscription} from "rxjs/Subscription";
import {Observable} from "rxjs/Observable";
import {BehaviorSubject} from "rxjs/BehaviorSubject";

/** @internalapi */
interface TransEvt { evt: string, trans: Transition }
Expand Down
2 changes: 1 addition & 1 deletion src/ng2/directives/uiView.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @module directives */ /** */
/** @ng2api @module directives */ /** */
import {
Component, ComponentFactoryResolver, ViewContainerRef, Input, ComponentRef, Type,
ReflectiveInjector, ViewChild, Injector, Inject
Expand Down
2 changes: 1 addition & 1 deletion src/ng2/interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @module state */ /** */
/** @ng2api @module state */ /** */
import {StateDeclaration, _ViewDeclaration} from "ui-router-core";
import {Transition} from "ui-router-core";
import {Type, OpaqueToken} from "@angular/core";
Expand Down
30 changes: 22 additions & 8 deletions src/ng2/lazyLoadNgModule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @module core */ /** */
/** @ng2api @module core */ /** */
import {NgModuleFactoryLoader, NgModuleRef, Injector, NgModuleFactory, Type, Compiler} from "@angular/core";
import {Transition, LazyLoadResult, UIRouter, Resolvable, NATIVE_INJECTOR_TOKEN, isString} from "ui-router-core";
import {RootModule, StatesModule, UIROUTER_ROOT_MODULE, UIROUTER_MODULE_TOKEN} from "./uiRouterNgModule";
Expand Down Expand Up @@ -105,25 +105,39 @@ export function applyNgModule(transition: Transition, ng2Module: NgModuleRef<any
let originalName = transition.to().name;
let originalState = uiRouter.stateRegistry.get(originalName);

let rootModules: RootModule[] = injector.get(UIROUTER_ROOT_MODULE);
let parentRootModules: RootModule[] = parentInjector.get(UIROUTER_ROOT_MODULE);
let newRootModules = rootModules.filter(module => parentRootModules.indexOf(module) === -1);
let newRootModules: RootModule[] = multiProviderParentChildDelta(parentInjector, injector, UIROUTER_ROOT_MODULE);

if (newRootModules.length) {
console.log(rootModules);
console.log(newRootModules);
throw new Error('Lazy loaded modules should not contain a UIRouterModule.forRoot() module');
}

let modules: StatesModule[] = injector.get(UIROUTER_MODULE_TOKEN);
modules.forEach(module => applyModuleConfig(uiRouter, injector, module));
let newModules: RootModule[] = multiProviderParentChildDelta(parentInjector, injector, UIROUTER_MODULE_TOKEN);
newModules.forEach(module => applyModuleConfig(uiRouter, injector, module));

let replacementState = uiRouter.stateRegistry.get(originalName);
if (replacementState === originalState) {
throw new Error(`The module that was lazy loaded by activating ${originalName} should also have a ui-router state named '${originalName}'`);
throw new Error(`The Future State named '${originalName}' lazy loaded an NgModule. That NgModule should also have a UIRouterModule.forChild() state named '${originalName}' to replace the Future State, but it did not.`);
}

// Supply the newly loaded states with the Injector from the lazy loaded NgModule
replacementState.$$state().resolvables.push(Resolvable.fromData(NATIVE_INJECTOR_TOKEN, injector));

return {};
}

/**
* Returns the new dependency injection values from the Child Injector
*
* When a DI token is defined as multi: true, the child injector
* can add new values for the token.
*
* This function returns the values added by the child injector, and excludes all values from the parent injector.
*
* @internalapi
*/
export function multiProviderParentChildDelta(parent: Injector, child: Injector, token: any) {
let childVals: RootModule[] = child.get(token);
let parentVals: RootModule[] = parent.get(token);
return childVals.filter(val => parentVals.indexOf(val) === -1);
}
3 changes: 2 additions & 1 deletion src/ng2/rx.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @module ng2 */ /** */
import {Observable, ReplaySubject} from "rxjs/Rx";
import {Observable} from "rxjs/Observable";
import {ReplaySubject} from "rxjs/ReplaySubject";
import {Transition} from "ui-router-core";
import {UIRouter} from "ui-router-core";
import {StateDeclaration} from "ui-router-core";
Expand Down
2 changes: 1 addition & 1 deletion src/ng2/uiRouterNgModule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @module core */ /** */
/** @ng2api @module core */ /** */
import {Ng2StateDeclaration} from "./interface";
import {NgModule, OpaqueToken, ModuleWithProviders, ANALYZE_FOR_ENTRY_COMPONENTS, Provider, Type} from "@angular/core";
import {CommonModule} from "@angular/common";
Expand Down
35 changes: 1 addition & 34 deletions tsconfig.typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,8 @@
"sourceMap": false
},
"files": [
"src/ng2.ts",
"../ui-router-core/src/index.ts",
"../ui-router-core/src/interface.ts",
"../ui-router-core/src/globals.ts",
"../ui-router-core/src/router.ts",
"../ui-router-core/src/common/glob.ts",
"../ui-router-core/src/common/trace.ts",
"../ui-router-core/src/params/module.ts",
"../ui-router-core/src/params/interface.ts",
"../ui-router-core/src/resolve/interface.ts",
"../ui-router-core/src/resolve/resolvable.ts",
"../ui-router-core/src/state/interface.ts",
"../ui-router-core/src/state/module.ts",
"../ui-router-core/src/state/stateObject.ts",
"../ui-router-core/src/state/stateRegistry.ts",
"../ui-router-core/src/state/stateService.ts",
"../ui-router-core/src/state/targetState.ts",
"../ui-router-core/src/transition/module.ts",
"../ui-router-core/src/transition/interface.ts",
"../ui-router-core/src/transition/transition.ts",
"../ui-router-core/src/transition/transitionService.ts",
"../ui-router-core/src/url/module.ts",
"../ui-router-core/src/url/urlMatcher.ts",
"../ui-router-core/src/url/urlMatcherFactory.ts",
"../ui-router-core/src/url/urlRouter.ts",
"../ui-router-core/src/view/module.ts",
"../ui-router-core/src/view/view.ts",
"src/ng2/directives/directives.ts",
"src/ng2/directives/uiSref.ts",
"src/ng2/directives/uiSrefActive.ts",
"src/ng2/directives/uiSrefStatus.ts",
"src/ng2/directives/uiView.ts",
"src/ng2/lazyLoadNgModule.ts",
"src/ng2/uiRouterNgModule.ts",
"src/ng2/interface.ts",
"src/index.ts",
"node_modules/typescript/lib/lib.es6.d.ts"
]
}

0 comments on commit 75cc29b

Please sign in to comment.