-
-
Notifications
You must be signed in to change notification settings - Fork 429
/
App.tsx
45 lines (36 loc) · 1.1 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import React from 'react';
import FBEmitter from "fbemitter";
import GreetingStore from '../stores/GreetingStore';
import GreetingState from '../types/GreetingState';
import WhoToGreet from './WhoToGreet';
import Greeting from './Greeting';
class App extends React.Component<{}, GreetingState> {
eventSubscription: FBEmitter.EventSubscription;
constructor(props: {}) {
super(props);
this.state = this.getStateFromStores();
}
private onChange = () => {
this.setState(this.getStateFromStores());
}
public componentWillMount() {
this.eventSubscription = GreetingStore.addChangeListener(this.onChange);
}
public componentWillUnmount() {
this.eventSubscription.remove();
}
render() {
const { greetings, newGreeting } = this.state;
return (
<div className="container-fluid">
<h1>Hello People!</h1>
<WhoToGreet newGreeting={ newGreeting } />
{ greetings.map((g, index) => <Greeting key={ index } targetOfGreeting={ g } />) }
</div>
);
}
private getStateFromStores() {
return GreetingStore.getState();
}
}
export default App;