From b0a672fa5e89dda8152ecab171b29b9326aced6f Mon Sep 17 00:00:00 2001 From: Chris Thielen Date: Fri, 20 Jan 2017 14:22:48 -0600 Subject: [PATCH] feat(rx): Move reactive extension to its own project at http://github.com/ui-router/rx --- package.json | 3 ++- src/directives/uiSref.ts | 21 +++++---------- src/index.ts | 1 - src/providers.ts | 2 +- src/rx.ts | 55 ---------------------------------------- 5 files changed, 10 insertions(+), 72 deletions(-) delete mode 100644 src/rx.ts diff --git a/package.json b/package.json index 710ae7ed2..a5a61ebdb 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,8 @@ "main": "lib/index.js", "typings": "lib/index.d.ts", "dependencies": { - "ui-router-core": "=3.1.1" + "ui-router-core": "=3.1.1", + "ui-router-rx": "=0.2.0" }, "peerDependencies": { "@angular/common": "^2.0.0", diff --git a/src/directives/uiSref.ts b/src/directives/uiSref.ts index 2ff5434f4..9df40ab97 100644 --- a/src/directives/uiSref.ts +++ b/src/directives/uiSref.ts @@ -1,17 +1,10 @@ -/** @ng2api @module directives */ /** */ -import {UIRouter, UIRouterGlobals} from "ui-router-core"; -import {Directive, Inject, Input} from "@angular/core"; -import {Optional} from "@angular/core"; -import {ElementRef} from "@angular/core"; -import {Renderer} from "@angular/core"; -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 {ReplaySubject} from 'rxjs/ReplaySubject'; -import {Subscription} from 'rxjs/Subscription'; -import {TargetState} from "ui-router-core"; -import "../rx"; +/** @ng2api @module directives */ +/** */ +import { UIRouter, UIRouterGlobals, extend, Obj, TransitionOptions, Globals, TargetState } from "ui-router-core"; +import { Directive, Inject, Input, Optional, ElementRef, Renderer } from "@angular/core"; +import { UIView, ParentUIViewInject } from "./uiView"; +import { ReplaySubject } from "rxjs/ReplaySubject"; +import { Subscription } from "rxjs/Subscription"; /** * @internalapi diff --git a/src/index.ts b/src/index.ts index f4ad67e18..94cf7d49b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,4 +21,3 @@ export * from "./directives/directives"; export * from "./location/uiRouterLocation"; export * from "./statebuilders/views"; export * from "./lazyLoad/lazyLoadNgModule"; -export * from "./rx"; diff --git a/src/providers.ts b/src/providers.ts index 9a7550af1..82dfe1c41 100644 --- a/src/providers.ts +++ b/src/providers.ts @@ -96,10 +96,10 @@ import { Ng2ViewDeclaration } from "./interface"; import { applyRootModuleConfig, applyModuleConfig } from "./uiRouterConfig"; import { UIRouterLocation } from "./location/uiRouterLocation"; import { RootModule, StatesModule, UIROUTER_ROOT_MODULE, UIROUTER_MODULE_TOKEN } from "./uiRouterNgModule"; -import { UIRouterRx } from "./rx"; import { servicesPlugin } from "ui-router-core/lib/vanilla"; import { ServicesPlugin } from "ui-router-core/lib/vanilla/interface"; import { ng2LazyLoadBuilder } from "./statebuilders/lazyLoad"; +import { UIRouterRx } from "ui-router-rx"; /** * This is a factory function for a UIRouter instance diff --git a/src/rx.ts b/src/rx.ts deleted file mode 100644 index 0e8dcd2d4..000000000 --- a/src/rx.ts +++ /dev/null @@ -1,55 +0,0 @@ -/** @module ng2 */ /** */ -import {Observable} from "rxjs/Observable"; -import {ReplaySubject} from "rxjs/ReplaySubject"; -import {Transition} from "ui-router-core"; -import {UIRouter} from "ui-router-core"; -import {StateDeclaration, UIRouterPlugin} from "ui-router-core"; - -export interface StatesChangedEvent { - currentStates: StateDeclaration[]; - registered: StateDeclaration[]; - deregistered: StateDeclaration[]; -} - -declare module 'ui-router-core/lib/globals' { - interface UIRouterGlobals { - states$?: Observable; - start$?: Observable; - success$?: Observable; - params$?: Observable<{ [paramName: string]: any }>; - } -} - -/** Augments UIRouterGlobals with observables for transition starts, successful transitions, and state parameters */ -export class UIRouterRx implements UIRouterPlugin { - name = 'ui-router-rx'; - private deregisterFns: Function[] = []; - - constructor(router: UIRouter) { - let start$ = new ReplaySubject(1); - let success$ = > start$.mergeMap((t: Transition) => t.promise.then(() => t)); - let params$ = success$.map((transition: Transition) => transition.params()); - - let states$ = new ReplaySubject(1); - function onStatesChangedEvent(event: string, states: StateDeclaration[]) { - let changeEvent = { - currentStates: router.stateRegistry.get(), - registered: [], - deregistered: [] - }; - - if (event) changeEvent[event] = states; - states$.next(changeEvent); - } - - this.deregisterFns.push(router.transitionService.onStart({}, transition => start$.next(transition))); - this.deregisterFns.push(router.stateRegistry.onStatesChanged(onStatesChangedEvent)); - onStatesChangedEvent(null, null); - Object.assign(router.globals, {start$, success$, params$, states$}); - } - - dispose() { - this.deregisterFns.forEach(deregisterFn => deregisterFn()); - this.deregisterFns = []; - } -}