Skip to content

Commit

Permalink
fix(ZoneOperators): Remove hard dependency on Angular 2
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeRyanDev committed Jun 17, 2016
1 parent b7dbcce commit 2d05ecc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
9 changes: 4 additions & 5 deletions lib/operator/enterZone.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import { NgZone } from '@angular/core';
import { Operator } from 'rxjs/Operator';
import { Subscriber } from 'rxjs/Subscriber';
import { Observable } from 'rxjs/Observable';

export interface EnterZoneSignature<T> {
(zone: NgZone): Observable<T>;
(zone: { run: (fn: any) => any }): Observable<T>;
}

export function enterZone<T>(zone: NgZone): Observable<T> {
export function enterZone<T>(zone: { run: (fn: any) => any }): Observable<T> {
return this.lift(new EnterZoneOperator(zone));
}

export class EnterZoneOperator<T> implements Operator<T, T> {
constructor(private _zone: NgZone) { }
constructor(private _zone: { run: (fn: any) => any }) { }

call(subscriber: Subscriber<T>, source: any): any {
return source._subscribe(new EnterZoneSubscriber(subscriber, this._zone));
}
}

class EnterZoneSubscriber<T> extends Subscriber<T> {
constructor(destination: Subscriber<T>, private _zone: NgZone) {
constructor(destination: Subscriber<T>, private _zone: { run: (fn: any) => any }) {
super(destination);
}

Expand Down
9 changes: 4 additions & 5 deletions lib/operator/leaveZone.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import { NgZone } from '@angular/core';
import { Operator } from 'rxjs/Operator';
import { Subscriber } from 'rxjs/Subscriber';
import { Observable } from 'rxjs/Observable';

export function leaveZone<T>(zone: NgZone): Observable<T> {
export function leaveZone<T>(zone: { runOutsideAngular: (fn: any) => any }): Observable<T> {
return this.lift(new LeaveZoneOperator(zone));
}

export interface LeaveZoneSignature<T> {
(zone: NgZone): Observable<T>;
(zone: { runOutsideAngular: (fn: any) => any }): Observable<T>;
}

export class LeaveZoneOperator<T> implements Operator<T, T> {
constructor(private _zone: NgZone) { }
constructor(private _zone: { runOutsideAngular: (fn: any) => any }) { }

call(subscriber: Subscriber<T>, source: any): any {
return source._subscribe(new LeaveZoneSubscriber(subscriber, this._zone));
}
}

class LeaveZoneSubscriber<T> extends Subscriber<T> {
constructor(destination: Subscriber<T>, private _zone: NgZone) {
constructor(destination: Subscriber<T>, private _zone: { runOutsideAngular: (fn: any) => any }) {
super(destination);
}

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
],
"license": "MIT",
"peerDependencies": {
"rxjs": "5.0.0-beta.6",
"@angular/core": "^2.0.0-rc.1"
"rxjs": "5.0.0-beta.6"
},
"devDependencies": {
"@angular/common": "^2.0.0-rc.1",
Expand Down

0 comments on commit 2d05ecc

Please sign in to comment.