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

Commit 418210f

Browse files
committed
refactor(app): use async with RxPipe
1 parent 111fde5 commit 418210f

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/app/components/app.ts

+22-9
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,28 @@ import {GreetModel} from '../models/GreetModel';
3232
})
3333
@View({
3434
template: `
35+
<div>
3536
counter {{ counter }}
36-
<button (click)="incrementCounter()">Increment Counter from Component</button>
37+
38+
<div>
39+
<button (click)="incrementCounter()">
40+
Increment Counter from Component
41+
</button>
42+
<content></content>
43+
</div>
44+
45+
</div>
3746
`
3847
})
3948
export class Count {
49+
counter: number;
4050
counterIntent: CounterIntent;
4151
constructor(counterIntent: CounterIntent) {
4252
this.counterIntent = counterIntent;
4353
}
4454

4555
onChange(value) {
46-
console.log('CHANGE Count', value);
56+
console.log('CHANGE Count\n', JSON.stringify(value, null, 2));
4757
}
4858
incrementCounter() {
4959
this.counterIntent.incrementCounter();
@@ -62,21 +72,24 @@ export class Count {
6272
directives: [ routerDirectives, coreDirectives, Count ],
6373
template: `
6474
65-
<h1 class="title">{{ state.greeting }}</h1>
75+
<h1 class="title">Hello Reactive Angular 2</h1>
6676
6777
68-
<count [counter]="state.counter"></count>
69-
<button (click)="handleIncrement()">Increment Counter from App</button>
78+
<count [counter]="state.counter">
79+
<button (click)="handleIncrement()">Increment Counter from App</button>
80+
</count>
7081
7182
<h2>Greet {{ state.greeting }}</h2>
7283
<div>
7384
<button (^click)="toggleGreet()">Greet {{ state.greeting }} </button>
7485
</div>
75-
<pre>AppState = {{ state | json }}</pre>
86+
<pre>state = {{ state | json }}</pre>
87+
<pre>appState = {{ appState | async | json }}</pre>
7688
`
7789
})
7890
export class App {
7991
state: any;
92+
appState: any;
8093
// public isn't working for me here :/
8194
counter: CounterModel; counterIntent: CounterIntent;
8295
greet: GreetModel; greetIntent: GreetIntent;
@@ -87,13 +100,13 @@ export class App {
87100

88101
this.state = {};
89102

90-
var appState = Rx.Observable.merge(
103+
this.appState = Rx.Observable.merge(
91104
this.counter.subject.toRx(),
92105
this.greet.subject.toRx()
93106
);
94107

95108

96-
appState.subscribe(results => {
109+
this.appState.subscribe(results => {
97110
this.state = Object.assign({}, this.state, results)
98111
});
99112

@@ -108,7 +121,7 @@ export class App {
108121
}
109122
// doesn't work at the moment
110123
onChange(value) {
111-
console.log('CHANGE App', value);
124+
console.log('CHANGE App\n', JSON.stringify(value, null, 2));
112125
}
113126
}
114127

0 commit comments

Comments
 (0)