@@ -7,6 +7,7 @@ import {Observable} from 'angular2/src/facade/async';
7
7
import { RouteConfig , Router , RouterOutlet , RouterLink } from 'angular2/router' ;
8
8
var routerDirectives = [ RouterOutlet , RouterLink ] ;
9
9
import { BrowserLocation } from 'angular2/src/router/browser_location' ;
10
+ import * as Rx from 'rx' ;
10
11
11
12
// A simple example of a Component using a Service
12
13
// import {Todo} from './todo';
@@ -17,6 +18,9 @@ import {BrowserLocation} from 'angular2/src/router/browser_location';
17
18
import { CounterIntent } from '../intents/CounterIntent' ;
18
19
import { CounterModel } from '../models/CounterModel' ;
19
20
21
+ import { GreetIntent } from '../intents/GreetIntent' ;
22
+ import { GreetModel } from '../models/GreetModel' ;
23
+
20
24
21
25
@Component ( {
22
26
selector : 'count' ,
@@ -38,8 +42,8 @@ export class Count {
38
42
this . counterIntent = counterIntent ;
39
43
}
40
44
41
- onChange ( wat ) {
42
- console . log ( 'CHANGE' , wat ) ;
45
+ onChange ( value ) {
46
+ console . log ( 'CHANGE Count ' , value ) ;
43
47
}
44
48
incrementCounter ( ) {
45
49
this . counterIntent . incrementCounter ( ) ;
@@ -55,47 +59,56 @@ export class Count {
55
59
} )
56
60
@View ( {
57
61
// needed in order to tell Angular's compiler what's in the template
58
- directives : [ routerDirectives , Count ] ,
62
+ directives : [ routerDirectives , coreDirectives , Count ] ,
59
63
template : `
60
64
61
- <h1 class="title">Hello {{ name }}</h1>
65
+ <h1 class="title">{{ state.greeting }}</h1>
62
66
63
67
64
68
<count [counter]="state.counter"></count>
65
69
<button (click)="handleIncrement()">Increment Counter from App</button>
66
70
67
-
68
-
69
- <pre>AppState = {{ model.subject | async | json }}</pre>
71
+ <h2>Greet {{ state.greeting }}</h2>
72
+ <div>
73
+ <button (^click)="toggleGreet()">Greet {{ state.greeting }} </button>
74
+ </div>
75
+ <pre>AppState = {{ state | json }}</pre>
70
76
`
71
77
} )
72
78
export class App {
73
- name : string ;
74
- state : Object ;
75
- model : CounterModel ; counterIntent : CounterIntent ;
76
- constructor ( model : CounterModel , counterIntent : CounterIntent ) {
77
- this . model = model ; this . counterIntent = counterIntent ;
78
-
79
- this . name = 'Angular 2' ;
80
- this . state = { counter : 0 } ;
81
-
82
- this . model . subject . observer ( { next : ( state ) => this . state = state } ) ;
83
-
84
- // var AppObservable = Rx.Observable.combineLatest([
85
- // Counter.subject,
86
- // OtherModel.subject
87
- // ],
88
- // (Counter, OtherModel) => {
89
- // return { Counter, OtherModel
90
- // };
91
- // }
92
- // );
79
+ state : any ;
80
+ // public isn't working for me here :/
81
+ counter : CounterModel ; counterIntent : CounterIntent ;
82
+ greet : GreetModel ; greetIntent : GreetIntent ;
83
+ constructor ( counter : CounterModel , counterIntent : CounterIntent ,
84
+ greet : GreetModel , greetIntent : GreetIntent ) {
85
+ this . counter = counter ; this . counterIntent = counterIntent ;
86
+ this . greet = greet ; this . greetIntent = greetIntent ;
87
+
88
+ this . state = { } ;
89
+
90
+ var appState = Rx . Observable . merge (
91
+ this . counter . subject . toRx ( ) ,
92
+ this . greet . subject . toRx ( )
93
+ ) ;
94
+
95
+
96
+ appState . subscribe ( results => {
97
+ this . state = Object . assign ( { } , this . state , results )
98
+ } ) ;
99
+
93
100
}
94
101
handleIncrement ( ) {
102
+ console . log ( 'CHANGE App' ) ;
95
103
this . counterIntent . incrementCounter ( ) ;
96
104
}
97
- onChange ( wat ) {
98
- console . log ( 'CHANGE TOP' , wat ) ;
105
+ toggleGreet ( ) {
106
+ console . log ( 'CHANGE App' ) ;
107
+ this . greetIntent . toggleGreet ( ) ;
108
+ }
109
+ // doesn't work at the moment
110
+ onChange ( value ) {
111
+ console . log ( 'CHANGE App' , value ) ;
99
112
}
100
113
}
101
114
0 commit comments