, NgZone, , - .
, :
import { Subscription } from 'rxjs/Subscription';
import { Scheduler } from 'rxjs/Scheduler';
import { NgZone } from '@angular/core';
class LeaveZoneSchduler {
constructor(private zone: NgZone, private scheduler: Scheduler) { }
schedule(...args: any[]): Subscription {
return this.zone.runOutsideAngular(() =>
this.scheduler.schedule.apply(this.scheduler, args)
);
}
}
class EnterZoneScheduler {
constructor(private zone: NgZone, private scheduler: Scheduler) { }
schedule(...args: any[]): Subscription {
return this.zone.run(() =>
this.scheduler.schedule.apply(this.scheduler, args)
);
}
}
export function leaveZone(zone: NgZone, scheduler: Scheduler): Scheduler {
return new LeaveZoneSchduler(zone, scheduler) as any;
}
export function enterZone(zone: NgZone, scheduler: Scheduler): Scheduler {
return new EnterZoneScheduler(zone, scheduler) as any;
}
, (, asap
async
), :
import { async } from 'rxjs/scheduler/async';
import { enterZone, leaveZone } from './util';
actions$.ofType('[Light] Turn On')
.bufferTime(300, leaveZone(this.ngZone, async))
.filter(messages => messages.length > 0)
.observeOn(enterZone(this.ngZone, async))
, (, bufferTime
, debounceTime
, Observable.timer
..) . observeOn
, - .