@@ -108,8 +108,6 @@ import {
108108 makeDefaultRasterLayerAdjustments ,
109109} from './util' ;
110110
111- type CanvasDeletedPayloadAction = PayloadAction < { id : string } > ;
112-
113111const getInitialCanvasState = ( id : string , name : string ) : CanvasState => ( {
114112 id,
115113 name,
@@ -155,7 +153,7 @@ const getInitialCanvasesHistoryState = (): CanvasesStateWithHistory => {
155153 } ;
156154} ;
157155
158- const slice = createSlice ( {
156+ const canvasesSlice = createSlice ( {
159157 name : 'canvas' ,
160158 initialState : getInitialCanvasesHistoryState ( ) ,
161159 reducers : {
@@ -197,7 +195,7 @@ const slice = createSlice({
197195
198196 canvas . name = name ;
199197 } ,
200- canvasDeleted : ( state , action : CanvasDeletedPayloadAction ) => {
198+ canvasDeleted : ( state , action : PayloadAction < { id : string } > ) => {
201199 const { id } = action . payload ;
202200
203201 if ( state . canvases . length === 1 ) {
@@ -1868,7 +1866,7 @@ export const {
18681866 canvasSelected,
18691867 canvasNameChanged,
18701868 canvasDeleted,
1871- } = slice . actions ;
1869+ } = canvasesSlice . actions ;
18721870
18731871export const {
18741872 canvasMetadataRecalled,
@@ -1968,6 +1966,8 @@ export const {
19681966 // inpaintMaskRecalled,
19691967} = canvasSlice . actions ;
19701968
1969+ const isCanvasSliceAction = isAnyOf ( ...Object . values ( canvasSlice . actions ) ) ;
1970+
19711971let filter = true ;
19721972
19731973const canvasUndoableConfig : UndoableOptions < CanvasState , UnknownAction > = {
@@ -1977,7 +1977,7 @@ const canvasUndoableConfig: UndoableOptions<CanvasState, UnknownAction> = {
19771977 clearHistoryType : canvasClearHistory . type ,
19781978 filter : ( action , _state , _history ) => {
19791979 // Ignore both all actions from other slices and canvas management actions
1980- if ( ! action . type . startsWith ( slice . name ) ) {
1980+ if ( ! action . type . startsWith ( canvasSlice . name ) ) {
19811981 return false ;
19821982 }
19831983 // Throttle rapid actions of the same type
@@ -1990,11 +1990,15 @@ const canvasUndoableConfig: UndoableOptions<CanvasState, UnknownAction> = {
19901990
19911991const undoableCanvasReducer = undoable ( canvasSlice . reducer , canvasUndoableConfig ) ;
19921992
1993- export const undoableCanvasSliceReducer = (
1993+ export const undoableCanvasesReducer = (
19941994 state : CanvasesStateWithHistory ,
19951995 action : UnknownAction
19961996) : CanvasesStateWithHistory => {
1997- state = slice . reducer ( state , action ) ;
1997+ state = canvasesSlice . reducer ( state , action ) ;
1998+
1999+ if ( ! isCanvasSliceAction ( action ) ) {
2000+ return state ;
2001+ }
19982002
19992003 return {
20002004 ...state ,
@@ -2004,28 +2008,14 @@ export const undoableCanvasSliceReducer = (
20042008 } ;
20052009} ;
20062010
2007- export const canvasSliceConfig : SliceConfig < typeof slice , CanvasesStateWithHistory , CanvasesStateWithoutHistory > = {
2008- slice,
2011+ export const canvasSliceConfig : SliceConfig <
2012+ typeof canvasesSlice ,
2013+ CanvasesStateWithHistory ,
2014+ CanvasesStateWithoutHistory
2015+ > = {
2016+ slice : canvasesSlice ,
20092017 getInitialState : getInitialCanvasesState ,
20102018 schema : zCanvasesStateWithHistory ,
2011- undoableConfig : {
2012- unwrapState : ( state ) => {
2013- return {
2014- _version : state . _version ,
2015- selectedCanvasId : state . selectedCanvasId ,
2016- canvases : state . canvases . map ( ( canvas ) => canvas . present ) ,
2017- } ;
2018- } ,
2019- wrapState : ( state ) => {
2020- const canvasesState = state as CanvasesStateWithoutHistory ;
2021-
2022- return {
2023- _version : canvasesState . _version ,
2024- selectedCanvasId : canvasesState . selectedCanvasId ,
2025- canvases : canvasesState . canvases . map ( ( canvas ) => newHistory ( [ ] , canvas , [ ] ) ) ,
2026- } ;
2027- } ,
2028- } ,
20292019 persistConfig : {
20302020 migrate : ( state ) => {
20312021 assert ( isPlainObject ( state ) ) ;
@@ -2048,6 +2038,22 @@ export const canvasSliceConfig: SliceConfig<typeof slice, CanvasesStateWithHisto
20482038 }
20492039 return zCanvasesStateWithoutHistory . parse ( state ) ;
20502040 } ,
2041+ wrapState : ( state ) => {
2042+ const canvasesState = state as CanvasesStateWithoutHistory ;
2043+
2044+ return {
2045+ _version : canvasesState . _version ,
2046+ selectedCanvasId : canvasesState . selectedCanvasId ,
2047+ canvases : canvasesState . canvases . map ( ( canvas ) => newHistory ( [ ] , canvas , [ ] ) ) ,
2048+ } ;
2049+ } ,
2050+ unwrapState : ( state ) => {
2051+ return {
2052+ _version : state . _version ,
2053+ selectedCanvasId : state . selectedCanvasId ,
2054+ canvases : state . canvases . map ( ( canvas ) => canvas . present ) ,
2055+ } ;
2056+ } ,
20512057 } ,
20522058} ;
20532059
0 commit comments