-
Notifications
You must be signed in to change notification settings - Fork 860
Expand file tree
/
Copy pathScreenBase.js
More file actions
37 lines (28 loc) · 750 Bytes
/
ScreenBase.js
File metadata and controls
37 lines (28 loc) · 750 Bytes
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
'use strict';
import { Component } from 'react';
import CalculatorStore from '../stores/CalculatorStore';
function getCalculatorState() {
return {
displayScreen: CalculatorStore.getDisplayScreen()
};
}
class Screen extends Component {
constructor(props) {
super(props);
this.state = {
displayScreen: CalculatorStore.getDisplayScreen()
};
// Bind callback methods to make `this` the correct context.
this._onChange = this._onChange.bind(this);
}
componentDidMount() {
CalculatorStore.addChangeListener(this._onChange);
}
componentWillUnmount() {
CalculatorStore.removeChangeListener(this._onChange);
}
_onChange() {
this.setState(getCalculatorState());
}
}
export default Screen;