Replace EventEmitter with typed EventDispatcher

This commit is contained in:
Thomas Nordquist
2019-01-06 13:49:20 +01:00
parent 32c3079821
commit 260f31fea0
5 changed files with 30 additions and 49 deletions

View File

@@ -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() {

View File

@@ -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) => {