Last active
April 30, 2018 10:55
-
-
Save Stuff90/9cd4191d158d066ca62389fe65425384 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Subject } from 'rxjs/Subject'; | |
import { takeUntil } from 'rxjs/operators'; | |
import { Observable } from 'rxjs/Observable'; | |
import { DataSource } from '@angular/cdk/collections'; | |
export class ReactiveDataSource<T> extends DataSource<T> { | |
private _disconnector: Subject<void> = new Subject(); | |
private _source: Observable<T[]>; | |
constructor(source: Observable<T[]>) { | |
super(); | |
this._source = source; | |
} | |
connect(): Observable<T[]> { | |
return this._source.pipe(takeUntil(this._disconnector)); | |
} | |
disconnect(): void { | |
this._disconnector.complete(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment