Replace EventEmitter with typed EventDispatcher
This commit is contained in:
@@ -22,12 +22,8 @@ interface State {
|
||||
}
|
||||
|
||||
class Sidebar extends React.Component<Props, State> {
|
||||
private updateNode = (node: q.TreeNode) => {
|
||||
if (!node) {
|
||||
this.setState(this.state)
|
||||
} else {
|
||||
this.setState({ node })
|
||||
}
|
||||
private updateNode = () => {
|
||||
this.setState(this.state)
|
||||
}
|
||||
|
||||
constructor(props: any) {
|
||||
@@ -58,17 +54,13 @@ class Sidebar extends React.Component<Props, State> {
|
||||
}
|
||||
|
||||
private registerUpdateListener(node: q.TreeNode) {
|
||||
node.on(q.TreeNodeUpdateEvents.merge, this.updateNode)
|
||||
node.on(q.TreeNodeUpdateEvents.message, this.updateNode)
|
||||
node.onMerge.subscribe(this.updateNode)
|
||||
node.onMessage.subscribe(this.updateNode)
|
||||
}
|
||||
|
||||
private removeUpdateListener(node: q.TreeNode) {
|
||||
node.removeListener(q.TreeNodeUpdateEvents.merge, this.updateNode)
|
||||
node.removeListener(q.TreeNodeUpdateEvents.message, this.updateNode)
|
||||
}
|
||||
|
||||
private open(): boolean {
|
||||
return true
|
||||
node.onMerge.unsubscribe(this.updateNode)
|
||||
node.onMessage.unsubscribe(this.updateNode)
|
||||
}
|
||||
|
||||
public render() {
|
||||
|
||||
@@ -13,23 +13,18 @@ interface State {
|
||||
}
|
||||
|
||||
class ValueRenderer extends React.Component<Props, State> {
|
||||
private updateNode: (node?: q.TreeNode | undefined) => void
|
||||
private updateNode: () => void
|
||||
constructor(props: any) {
|
||||
super(props)
|
||||
this.state = {}
|
||||
this.updateNode = (node) => {
|
||||
if (!node) {
|
||||
this.setState(this.state)
|
||||
} else {
|
||||
this.setState({ node })
|
||||
}
|
||||
this.updateNode = () => {
|
||||
this.setState(this.state)
|
||||
}
|
||||
}
|
||||
|
||||
public componentWillReceiveProps(nextProps: Props) {
|
||||
this.props.node && this.props.node.removeListener('update', this.updateNode)
|
||||
nextProps.node && nextProps.node.on('update', this.updateNode)
|
||||
nextProps.node && this.updateNode(nextProps.node)
|
||||
this.props.node && this.props.node.onMessage.unsubscribe(this.updateNode)
|
||||
nextProps.node && nextProps.node.onMessage.subscribe(this.updateNode)
|
||||
}
|
||||
|
||||
private style = (theme: Theme) => {
|
||||
|
||||
Reference in New Issue
Block a user