Skip to content
This repository was archived by the owner on Feb 17, 2024. It is now read-only.

Commit 111fde5

Browse files
committed
feat: include RxPipes in async as rxPipes
1 parent 22e07d5 commit 111fde5

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

src/app/bootstrap.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {bootstrap} from 'angular2/angular2';
77
// include any injectables
88
import {routerInjectables} from 'angular2/router';
99
import {shadowDomInjectables} from '../common/shadowDomInjectables';
10+
import {rxPipeRegistry} from '../common/rxPipes';
1011

1112
// Our injectables Services
1213
// import {appServicesInjectables} from './services/services';
@@ -22,5 +23,6 @@ bootstrap(App, [
2223
// shadowDomInjectables,
2324
// our servies
2425
// appServicesInjectables,
25-
modelInjectables
26+
modelInjectables,
27+
rxPipeRegistry
2628
]);

src/common/rxPipes.ts

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import {PipeFactory} from 'angular2/src/change_detection/pipes/pipe';
2+
import {async} from 'angular2/src/change_detection/change_detection';
3+
import {Pipe, PipeRegistry, defaultPipes} from 'angular2/change_detection';
4+
import {bind} from 'angular2/di';
5+
import {ObservablePipe} from 'angular2/pipes';
6+
import * as Rx from 'rx';
7+
8+
export function isObservable(obs) {
9+
return obs && obs.subscribe;
10+
}
11+
12+
export class RxPipe extends ObservablePipe {
13+
_subscription: any;
14+
_observable: any;
15+
constructor(ref) { super(ref); }
16+
supports(obs) { return isObservable(obs); }
17+
_subscribe(obs) {
18+
this._observable = obs;
19+
this._subscription = obs.subscribe(
20+
value => this._updateLatestValue(value),
21+
e => { throw e; }
22+
);
23+
}
24+
25+
}
26+
27+
export class RxPipeFactory extends PipeFactory {
28+
constructor() { super(); }
29+
30+
supports(obs) { return isObservable(obs); }
31+
32+
create(cdRef): Pipe { return new RxPipe(cdRef); }
33+
}
34+
35+
export var rxAsync = [ new RxPipeFactory() ].concat(async);
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+
];

src/custom_typings/ng2.d.ts

+26
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,32 @@ declare var global: any;
55
declare var zone: any;
66
declare var Zone: any;
77

8+
declare module "angular2/src/change_detection/pipes/pipe" {
9+
class PipeFactory {}
10+
}
11+
12+
declare module "angular2/src/change_detection/change_detection" {
13+
var async: any;
14+
}
15+
16+
declare module "angular2/change_detection" {
17+
class Pipe {}
18+
class PipeRegistry {
19+
constructor(pipes: any)
20+
}
21+
var defaultPipes: any;
22+
}
23+
24+
declare module "angular2/pipes" {
25+
class ObservablePipe {
26+
constructor(ref: any)
27+
_subscription: any;
28+
_observable: any;
29+
_updateLatestValue(value: any): any;
30+
_subscribe(obs: any): any;
31+
}
32+
}
33+
834
declare module 'angular2/src/services/url_resolver' {
935
class UrlResolver {}
1036
}

0 commit comments

Comments
 (0)