Skip to content

Commit

Permalink
fix(core): only import typing from zone.js
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaLiPassion committed May 5, 2018
1 parent d8c38a4 commit 03350ac
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions src/core/angularfire2.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
import { InjectionToken, NgZone } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';
import { queue } from 'rxjs/scheduler/queue';
import { isPlatformServer } from '@angular/common';
import { observeOn } from 'rxjs/operator/observeOn';
import 'rxjs/add/operator/first';

import {isPlatformServer} from '@angular/common';
import {InjectionToken, NgZone} from '@angular/core';
import firebase from '@firebase/app';
import { FirebaseApp, FirebaseOptions } from '@firebase/app-types';

import 'zone.js';
import 'rxjs/add/operator/first';
import {FirebaseApp, FirebaseOptions} from '@firebase/app-types';
import {Observable} from 'rxjs/Observable';
import {observeOn} from 'rxjs/operator/observeOn';
import {queue} from 'rxjs/scheduler/queue';
import {Subscription} from 'rxjs/Subscription';
import {} from 'zone.js';

export const FirebaseAppName = new InjectionToken<string>('angularfire2.appName');
export const FirebaseAppConfig = new InjectionToken<FirebaseOptions>('angularfire2.config');
export const FirebaseAppName =
new InjectionToken<string>('angularfire2.appName');
export const FirebaseAppConfig =
new InjectionToken<FirebaseOptions>('angularfire2.config');

// Put in database.ts when we drop database-depreciated
export const RealtimeDatabaseURL = new InjectionToken<string>('angularfire2.realtimeDatabaseURL');
export const RealtimeDatabaseURL =
new InjectionToken<string>('angularfire2.realtimeDatabaseURL');

export class FirebaseZoneScheduler {
constructor(public zone: NgZone, private platformId: Object) {}
schedule(...args: any[]): Subscription {
return <Subscription>this.zone.runGuarded(function() { return queue.schedule.apply(queue, args)});
return <Subscription>this.zone.runGuarded(function() {
return queue.schedule.apply(queue, args)
});
}
// TODO this is a hack, clean it up
keepUnstableUntilFirst<T>(obs$: Observable<T>) {
if (isPlatformServer(this.platformId)) {
return new Observable<T>(subscriber => {
const noop = () => {};
const task = Zone.current.scheduleMacroTask('firebaseZoneBlock', noop, {}, noop, noop);
obs$.first().subscribe(() => this.zone.runOutsideAngular(() => task.invoke()));
const task = Zone.current.scheduleMacroTask(
'firebaseZoneBlock', noop, {}, noop, noop);
obs$.first().subscribe(
() => this.zone.runOutsideAngular(() => task.invoke()));
return obs$.subscribe(subscriber);
});
} else {
Expand All @@ -39,11 +45,11 @@ export class FirebaseZoneScheduler {
return new Observable<T>(subscriber => {
return this.zone.runOutsideAngular(() => {
return obs$.subscribe(
value => this.zone.run(() => subscriber.next(value)),
error => this.zone.run(() => subscriber.error(error)),
() => this.zone.run(() => subscriber.complete()),
value => this.zone.run(() => subscriber.next(value)),
error => this.zone.run(() => subscriber.error(error)),
() => this.zone.run(() => subscriber.complete()),
);
});
});
}
}
}

0 comments on commit 03350ac

Please sign in to comment.