Update use status api with mount event

This commit is contained in:
2022-03-07 10:43:23 +08:00
parent 779076012f
commit 9bc8ddf061
6 changed files with 93 additions and 57 deletions
@@ -41,7 +41,6 @@ class ObjectCommand extends Component<IMixinStatusProps> {
className="command-item"
onClick={() => {
this.props.status ? this.props.status.newGroup() : undefined;
this.props.status ? this.props.status.model.draw() : undefined;
}}
>
<Icon iconName="WebAppBuilderFragmentCreate"></Icon>
@@ -50,7 +49,6 @@ class ObjectCommand extends Component<IMixinStatusProps> {
className="command-item"
onClick={() => {
this.props.status ? this.props.status.newRange() : undefined;
this.props.status ? this.props.status.model.draw() : undefined;
}}
>
<Icon iconName="CubeShape"></Icon>
@@ -65,7 +63,6 @@ class ObjectCommand extends Component<IMixinStatusProps> {
})
this.props.status.model.deleteObject(deleteId);
this.props.status.setFocusObject(new Set<ObjectID>());
this.props.status.model.draw();
}
}}
>
+2 -20
View File
@@ -1,33 +1,15 @@
import { Component, ReactNode } from "react";
import { DetailsList } from "@Component/DetailsList/DetailsList";
import { useStatus, IMixinStatusProps } from "@Context/Status";
import { useStatusWithEvent, IMixinStatusProps } from "@Context/Status";
import { useSetting, IMixinSettingProps } from "@Context/Setting";
import { Localization } from "@Component/Localization/Localization";
import { ObjectID } from "@Model/Renderer";
import "./ObjectList.scss";
@useSetting
@useStatus
@useStatusWithEvent("objectChange", "focusObjectChange")
class ObjectList extends Component<IMixinStatusProps & IMixinSettingProps> {
private handelChange = () => {
this.forceUpdate();
}
public componentDidMount(){
if (this.props.status) {
this.props.status.model.on("objectChange", this.handelChange);
this.props.status.on("focusObjectChange", this.handelChange);
}
}
public componentWillUnmount(){
if (this.props.status) {
this.props.status.model.off("objectChange", this.handelChange);
this.props.status.off("focusObjectChange", this.handelChange);
}
}
private renderList() {
const objList = this.props.status?.model.objectPool ?? [];