Guest User

Untitled

a guest
Aug 5th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. /// <reference path="../../typings/tsd.d.ts" />
  2. ///
  3. import {PipeFactory} from 'angular2/src/change_detection/pipes/pipe';
  4. import {async} from 'angular2/src/change_detection/change_detection';
  5. import {NullPipeFactory, Pipe, PipeRegistry, defaultPipes} from 'angular2/change_detection';
  6. import {bind} from 'angular2/di';
  7. import {ObservablePipe} from 'angular2/pipes';
  8. import * as Rx from 'rx';
  9.  
  10. export function isObservable(obs) {
  11. return obs && obs instanceof Rx.Observable;
  12. }
  13.  
  14. export class RxPipe extends ObservablePipe {
  15. _subscription: any;
  16. _observable: any;
  17. constructor(ref) { super(ref); }
  18. supports(obs) { return isObservable(obs); }
  19. _subscribe(obs) {
  20. this._observable = obs;
  21. this._subscription = obs.subscribe(
  22. value => this._updateLatestValue(value),
  23. e => { throw e; }
  24. );
  25. }
  26. }
  27.  
  28. export class RxPipeFactory extends PipeFactory {
  29. constructor() { super(); }
  30. supports(obs) { return isObservable(obs); }
  31. create(cdRef): Pipe { return new RxPipe(cdRef); }
  32. }
  33.  
  34. export var rxAsync = [ new RxPipeFactory() ].concat(async);
  35.  
  36.  
  37. export var rxPipes = Object.assign({}, defaultPipes, {
  38. 'async': rxAsync
  39. });
  40.  
  41. export var rxPipeRegistry = [
  42. bind(PipeRegistry).toValue(new PipeRegistry(rxPipes))
  43. ];
Add Comment
Please, Sign In to add comment