@@ -109,8 +109,6 @@ import {
109
109
makeDefaultRasterLayerAdjustments ,
110
110
} from './util' ;
111
111
112
- type CanvasDeletedPayloadAction = PayloadAction < { id : string } > ;
113
-
114
112
const getInitialCanvasState = ( id : string , name : string ) : CanvasState => ( {
115
113
id,
116
114
name,
@@ -156,7 +154,7 @@ const getInitialCanvasesHistoryState = (): CanvasesStateWithHistory => {
156
154
} ;
157
155
} ;
158
156
159
- const slice = createSlice ( {
157
+ const canvasesSlice = createSlice ( {
160
158
name : 'canvas' ,
161
159
initialState : getInitialCanvasesHistoryState ( ) ,
162
160
reducers : {
@@ -198,7 +196,7 @@ const slice = createSlice({
198
196
199
197
canvas . name = name ;
200
198
} ,
201
- canvasDeleted : ( state , action : CanvasDeletedPayloadAction ) => {
199
+ canvasDeleted : ( state , action : PayloadAction < { id : string } > ) => {
202
200
const { id } = action . payload ;
203
201
204
202
if ( state . canvases . length === 1 ) {
@@ -1869,7 +1867,7 @@ export const {
1869
1867
canvasSelected,
1870
1868
canvasNameChanged,
1871
1869
canvasDeleted,
1872
- } = slice . actions ;
1870
+ } = canvasesSlice . actions ;
1873
1871
1874
1872
export const {
1875
1873
canvasMetadataRecalled,
@@ -1969,6 +1967,8 @@ export const {
1969
1967
// inpaintMaskRecalled,
1970
1968
} = canvasSlice . actions ;
1971
1969
1970
+ const isCanvasSliceAction = isAnyOf ( ...Object . values ( canvasSlice . actions ) ) ;
1971
+
1972
1972
let filter = true ;
1973
1973
1974
1974
const canvasUndoableConfig : UndoableOptions < CanvasState , UnknownAction > = {
@@ -1978,7 +1978,7 @@ const canvasUndoableConfig: UndoableOptions<CanvasState, UnknownAction> = {
1978
1978
clearHistoryType : canvasClearHistory . type ,
1979
1979
filter : ( action , _state , _history ) => {
1980
1980
// 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 ) ) {
1982
1982
return false ;
1983
1983
}
1984
1984
// Throttle rapid actions of the same type
@@ -1991,11 +1991,15 @@ const canvasUndoableConfig: UndoableOptions<CanvasState, UnknownAction> = {
1991
1991
1992
1992
const undoableCanvasReducer = undoable ( canvasSlice . reducer , canvasUndoableConfig ) ;
1993
1993
1994
- export const undoableCanvasSliceReducer = (
1994
+ export const undoableCanvasesReducer = (
1995
1995
state : CanvasesStateWithHistory ,
1996
1996
action : UnknownAction
1997
1997
) : CanvasesStateWithHistory => {
1998
- state = slice . reducer ( state , action ) ;
1998
+ state = canvasesSlice . reducer ( state , action ) ;
1999
+
2000
+ if ( ! isCanvasSliceAction ( action ) ) {
2001
+ return state ;
2002
+ }
1999
2003
2000
2004
return {
2001
2005
...state ,
@@ -2005,28 +2009,14 @@ export const undoableCanvasSliceReducer = (
2005
2009
} ;
2006
2010
} ;
2007
2011
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 ,
2010
2018
getInitialState : getInitialCanvasesState ,
2011
2019
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
- } ,
2030
2020
persistConfig : {
2031
2021
migrate : ( state ) => {
2032
2022
assert ( isPlainObject ( state ) ) ;
@@ -2049,6 +2039,22 @@ export const canvasSliceConfig: SliceConfig<typeof slice, CanvasesStateWithHisto
2049
2039
}
2050
2040
return zCanvasesStateWithoutHistory . parse ( state ) ;
2051
2041
} ,
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
+ } ,
2052
2058
} ,
2053
2059
} ;
2054
2060
0 commit comments