Javascript React Redux在状态更新时不呈现

Javascript React Redux在状态更新时不呈现,javascript,reactjs,redux,Javascript,Reactjs,Redux,我有一个使用React/Redux构建的地图应用程序。在这个应用程序中,有移动对象的选项,我正在尝试构建一个撤销/重做功能。我已经为撤销设置了按键处理程序,它调用Redux操作创建者来增加(或减少)“currentMove”计数器。My render函数使用“this.props.layout.deskMoves[this.props.layout.currentDesk]”提取项目(桌子)数组。这已被外推到一个单独的函数中。我使用的拖动功能工作正常,可以移动桌面,然后更新数据库。它还更新了“d

我有一个使用React/Redux构建的地图应用程序。在这个应用程序中,有移动对象的选项,我正在尝试构建一个撤销/重做功能。我已经为撤销设置了按键处理程序,它调用Redux操作创建者来增加(或减少)“currentMove”计数器。My render函数使用
“this.props.layout.deskMoves[this.props.layout.currentDesk]”提取项目(桌子)数组。
这已被外推到一个单独的函数中。我使用的拖动功能工作正常,可以移动桌面,然后更新数据库。它还更新了“deskMoves”数组。但当我按下CTRL+Z时,“currentMoves”指针会正确更改,但桌子不会在新位置重新绘制。我无法找出问题所在,因为我已检查以确保我没有传递数组引用,而是使用spread操作符为每次移动创建数组的副本

以下是我的各种功能:

    handleKeyPress = (e) => {
        if (this.state.edit) {
            switch (e.code) {
                case 'KeyZ':
                    if (e.ctrlKey) this.props.Layout_Undo_Change();
                    e.cancelBubble = true;
                    break;
                case 'KeyY':
                    if (e.ctrlKey) this.props.Layout_Redo_Change();
                    e.cancelBubble = true;
                    break;
                default:
                    break;
            }
        }
    }
buildDesks=()=>{
const newScale=this.getScale();
const layout=this.props.layout;
const desks=this.getDesks();
让ret=desks.map((desk,index)=>{
设deskImg=null;
试一试{
让dImg=layout.deskTypes.find(
d=>parseInt(d.deskType)==parseInt(desk.deskType)
);
deskImg=dImg.deskImage;
}
捕获(ex){
控制台日志(ex);
}
const userName=desk.UserLogon!==(null | |?“”)?desk.UserLogon:“未分配”;
const top=Math.trunc(parseInt(parseInt(desk.y)*newScale));
const left=Math.trunc(parseInt(parseInt(desk.x)*newScale));
设imgStyle={
宽度:`${parseInt(parseInt(desk.width)*newScale)}px`,
高度:`${parseInt((parseInt(desk.height)*newScale))}px`,
转换:`rotate(${parseInt(desk.rotation)}deg)`,
位置:'绝对'
}
if(layout.currentDesk&&desk.id==layout.currentDesk.id){
imgStyle.border='2px固体青色';
}
constURL=`data:image/jpeg;base64,${deskImg}`;
试一试{
返回(
);
}
捕获(ex){
控制台日志(ex);
返回null;
}
});//桌子。地图
返回ret;
}//办公桌
render(){
if(this.props.layout.isload){
返回();
}
else if(this.props.layout.isLoadingMap){
const map=this.props.layout.maps[this.props.layout.currentMap];
const siteName=map.siteName;
返回(
);
}
else if(this.props.layout.mapload){
返回(
{this.showAdmin()}
{this.state.details}{this.props.layout.currentMove}
this.changeMap(e.target)}>
{this.buildMapOptions()}
{this.buildMap()}
{this.buildDesks()}
{this.showStatus()}
);
}
否则{
返回(
this.changeMap(e.target)}>
{this.buildMapOptions()}
);
}
}

一些进一步的信息:当我使用CTRL-Z时,在单击最近移动的桌子之前,什么都不会发生。在这一点上,它跳到它以前的位置。多次撤消对我移动的每一张桌子都有相同的效果。如果我多次撤消,它将仅在我单击每个桌子后才恢复。一些进一步的信息:当我使用CTRL-Z时,在我单击最近移动的桌子之前,不会发生任何事情。在这一点上,它跳到它以前的位置。多次撤消对我移动的每一张桌子都有相同的效果。如果我多次撤销,它将仅在我单击每个桌子后才恢复。
export const Layout_Undo_Change = () => (dispatch, getState) => {
    const state = getState();
    let current = state.layout.currentMove;

    if (current > 0)
        current--;

    return dispatch({
        type: ActionTypes.LAYOUT_SET_MOVES,
        payload: current
    });
}
buildDesks = () => {
        const newScale = this.getScale();
        const layout = this.props.layout;
        const desks = this.getDesks();

        let ret = desks.map((desk, index) => {
            let deskImg = null;
            try {
                let dImg = layout.deskTypes.find(
                    d => parseInt(d.deskType) === parseInt(desk.deskType)
                );
                deskImg = dImg.deskImage;
            }
            catch (ex) {
                console.log(ex);
            }
            const userName = desk.UserLogon !== (null || '') ? desk.UserLogon : "Unassigned";

            const top = Math.trunc(parseInt(parseInt(desk.y) * newScale));
            const left = Math.trunc(parseInt(parseInt(desk.x) * newScale));

            let imgStyle = {
                width: `${parseInt(parseInt(desk.width) * newScale)}px`,
                height: `${parseInt((parseInt(desk.height) * newScale))}px`,
                transform: `rotate(${parseInt(desk.rotation)}deg)`,
                position: 'absolute'
            }
            if (layout.currentDesk && desk.id === layout.currentDesk.id) {
                imgStyle.border = '2px solid cyan';
            }
            const url = `data:image/jpeg;base64,${deskImg}`;
            try {
                return (
                    <Draggable key={desk.id}
                        index={index}
                        enabled={this.state.edit}
                        left={left}
                        top={top}
                        onMove={this.updateProperties}
                        onStop={this.mouseUp}
                        onRightClick={this.rightClick}
                    >
                        <div style={{ position: 'relative' }} className='deskImg'>
                            <img style={imgStyle} alt={userName} src={url} />
                        </div>
                    </Draggable>
                );
            }
            catch (ex) {
                console.log(ex);
                return null;
            }
        });//desks.map
        return ret;
    }//buildDesks
render() {
        if (this.props.layout.isLoading) {
            return (<Loading title="Site Layout" />);
        }
        else if (this.props.layout.isLoadingMap) {
            const map = this.props.layout.maps[this.props.layout.currentMap];
            const siteName = map.SiteName;
            return (
                <Row>
                    <Col sm={1}></Col>
                    <Col sm={10} id="Layout_Map_Container">
                        <Loading title={"map '" + siteName + "'"} />
                    </Col>
                </Row>
            );
        }
        else if (this.props.layout.mapLoaded) {
            return (
                <div>

                    <Row>
                        <Col sm={1}>
                            {this.showAdmin()}
                        </Col>
                        <Col sm={10}>
                            {this.state.details} {this.props.layout.currentMove}
                        </Col>
                    </Row>
                    <Row>
                        <Col sm={1}>
                            <select onChange={(e) => this.changeMap(e.target)}>
                                {this.buildMapOptions()}
                            </select>
                        </Col>
                        <Col sm={10} id="Layout_Map_Container">
                            {this.buildMap()}
                            {this.buildDesks()}

                        </Col>
                    </Row >
                    {this.showStatus()}
                </div>
            );
        }
        else {
            return (
                <Row>
                    <Col sm={1}>
                        <select onChange={(e) => this.changeMap(e.target)}>
                            {this.buildMapOptions()}
                        </select>
                    </Col>
                    <Col sm={10} id="Layout_Map_Container">
                    </Col>
                </Row>
            );
        }
    }