@@ -109,8 +109,6 @@ import {
109109 makeDefaultRasterLayerAdjustments ,
110110} from './util' ;
111111
112- type CanvasDeletedPayloadAction = PayloadAction < { id : string } > ;
113-
114112const getInitialCanvasState = ( id : string , name : string ) : CanvasState => ( {
115113 id,
116114 name,
@@ -156,7 +154,7 @@ const getInitialCanvasesHistoryState = (): CanvasesStateWithHistory => {
156154 } ;
157155} ;
158156
159- const slice = createSlice ( {
157+ const canvasesSlice = createSlice ( {
160158 name : 'canvas' ,
161159 initialState : getInitialCanvasesHistoryState ( ) ,
162160 reducers : {
@@ -198,7 +196,7 @@ const slice = createSlice({
198196
199197 canvas . name = name ;
200198 } ,
201- canvasDeleted : ( state , action : CanvasDeletedPayloadAction ) => {
199+ canvasDeleted : ( state , action : PayloadAction < { id : string } > ) => {
202200 const { id } = action . payload ;
203201
204202 if ( state . canvases . length === 1 ) {
@@ -1869,7 +1867,7 @@ export const {
18691867 canvasSelected,
18701868 canvasNameChanged,
18711869 canvasDeleted,
1872- } = slice . actions ;
1870+ } = canvasesSlice . actions ;
18731871
18741872export const {
18751873 canvasMetadataRecalled,
@@ -1969,6 +1967,8 @@ export const {
19691967 // inpaintMaskRecalled,
19701968} = canvasSlice . actions ;
19711969
1970+ const isCanvasSliceAction = isAnyOf ( ...Object . values ( canvasSlice . actions ) ) ;
1971+
19721972let filter = true ;
19731973
19741974const canvasUndoableConfig : UndoableOptions < CanvasState , UnknownAction > = {
@@ -1978,7 +1978,7 @@ const canvasUndoableConfig: UndoableOptions<CanvasState, UnknownAction> = {
19781978 clearHistoryType : canvasClearHistory . type ,
19791979 filter : ( action , _state , _history ) => {
19801980 // Ignore both all actions from other slices and canvas management actions
1981- if ( ! action . type . startsWith ( slice . name ) ) {
1981+ if ( ! action . type . startsWith ( canvasSlice . name ) ) {
19821982 return false ;
19831983 }
19841984 // Throttle rapid actions of the same type
@@ -1991,11 +1991,15 @@ const canvasUndoableConfig: UndoableOptions<CanvasState, UnknownAction> = {
19911991
19921992const undoableCanvasReducer = undoable ( canvasSlice . reducer , canvasUndoableConfig ) ;
19931993
1994- export const undoableCanvasSliceReducer = (
1994+ export const undoableCanvasesReducer = (
19951995 state : CanvasesStateWithHistory ,
19961996 action : UnknownAction
19971997) : CanvasesStateWithHistory => {
1998- state = slice . reducer ( state , action ) ;
1998+ state = canvasesSlice . reducer ( state , action ) ;
1999+
2000+ if ( ! isCanvasSliceAction ( action ) ) {
2001+ return state ;
2002+ }
19992003
20002004 return {
20012005 ...state ,
@@ -2005,28 +2009,14 @@ export const undoableCanvasSliceReducer = (
20052009 } ;
20062010} ;
20072011
2008- export const canvasSliceConfig : SliceConfig < typeof slice , CanvasesStateWithHistory , CanvasesStateWithoutHistory > = {
2009- slice,
2012+ export const canvasSliceConfig : SliceConfig <
2013+ typeof canvasesSlice ,
2014+ CanvasesStateWithHistory ,
2015+ CanvasesStateWithoutHistory
2016+ > = {
2017+ slice : canvasesSlice ,
20102018 getInitialState : getInitialCanvasesState ,
20112019 schema : zCanvasesStateWithHistory ,
2012- undoableConfig : {
2013- unwrapState : ( state ) => {
2014- return {
2015- _version : state . _version ,
2016- selectedCanvasId : state . selectedCanvasId ,
2017- canvases : state . canvases . map ( ( canvas ) => canvas . present ) ,
2018- } ;
2019- } ,
2020- wrapState : ( state ) => {
2021- const canvasesState = state as CanvasesStateWithoutHistory ;
2022-
2023- return {
2024- _version : canvasesState . _version ,
2025- selectedCanvasId : canvasesState . selectedCanvasId ,
2026- canvases : canvasesState . canvases . map ( ( canvas ) => newHistory ( [ ] , canvas , [ ] ) ) ,
2027- } ;
2028- } ,
2029- } ,
20302020 persistConfig : {
20312021 migrate : ( state ) => {
20322022 assert ( isPlainObject ( state ) ) ;
@@ -2049,6 +2039,22 @@ export const canvasSliceConfig: SliceConfig<typeof slice, CanvasesStateWithHisto
20492039 }
20502040 return zCanvasesStateWithoutHistory . parse ( state ) ;
20512041 } ,
2042+ wrapState : ( state ) => {
2043+ const canvasesState = state as CanvasesStateWithoutHistory ;
2044+
2045+ return {
2046+ _version : canvasesState . _version ,
2047+ selectedCanvasId : canvasesState . selectedCanvasId ,
2048+ canvases : canvasesState . canvases . map ( ( canvas ) => newHistory ( [ ] , canvas , [ ] ) ) ,
2049+ } ;
2050+ } ,
2051+ unwrapState : ( state ) => {
2052+ return {
2053+ _version : state . _version ,
2054+ selectedCanvasId : state . selectedCanvasId ,
2055+ canvases : state . canvases . map ( ( canvas ) => canvas . present ) ,
2056+ } ;
2057+ } ,
20522058 } ,
20532059} ;
20542060
0 commit comments