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