@@ -2135,95 +2135,96 @@ class App extends React.Component<AppProps, AppState> {
21352135 } ) ;
21362136 } ;
21372137
2138- private syncActionResult = withBatchedUpdates (
2139- ( actionResult : ActionResult ) => {
2140- if ( this . unmounted || actionResult === false ) {
2141- return ;
2142- }
2138+ public syncActionResult = withBatchedUpdates ( ( actionResult : ActionResult ) => {
2139+ if ( this . unmounted || actionResult === false ) {
2140+ return ;
2141+ }
21432142
2144- let editingElement : AppState [ "editingElement" ] | null = null ;
2145- if ( actionResult . elements ) {
2146- actionResult . elements . forEach ( ( element ) => {
2147- if (
2148- this . state . editingElement ?. id === element . id &&
2149- this . state . editingElement !== element &&
2150- isNonDeletedElement ( element )
2151- ) {
2152- editingElement = element ;
2153- }
2154- } ) ;
2143+ if ( actionResult . storeAction === StoreAction . UPDATE ) {
2144+ this . store . shouldUpdateSnapshot ( ) ;
2145+ } else if ( actionResult . storeAction === StoreAction . CAPTURE ) {
2146+ this . store . shouldCaptureIncrement ( ) ;
2147+ }
21552148
2156- if ( actionResult . storeAction === StoreAction . UPDATE ) {
2157- this . store . shouldUpdateSnapshot ( ) ;
2158- } else if ( actionResult . storeAction === StoreAction . CAPTURE ) {
2159- this . store . shouldCaptureIncrement ( ) ;
2149+ let didUpdate = false ;
2150+
2151+ let editingElement : AppState [ "editingElement" ] | null = null ;
2152+ if ( actionResult . elements ) {
2153+ actionResult . elements . forEach ( ( element ) => {
2154+ if (
2155+ this . state . editingElement ?. id === element . id &&
2156+ this . state . editingElement !== element &&
2157+ isNonDeletedElement ( element )
2158+ ) {
2159+ editingElement = element ;
21602160 }
2161+ } ) ;
21612162
2162- this . scene . replaceAllElements ( actionResult . elements ) ;
2163- }
2163+ this . scene . replaceAllElements ( actionResult . elements ) ;
2164+ didUpdate = true ;
2165+ }
21642166
2165- if ( actionResult . files ) {
2166- this . files = actionResult . replaceFiles
2167- ? actionResult . files
2168- : { ...this . files , ...actionResult . files } ;
2169- this . addNewImagesToImageCache ( ) ;
2167+ if ( actionResult . files ) {
2168+ this . files = actionResult . replaceFiles
2169+ ? actionResult . files
2170+ : { ...this . files , ...actionResult . files } ;
2171+ this . addNewImagesToImageCache ( ) ;
2172+ }
2173+
2174+ if ( actionResult . appState || editingElement || this . state . contextMenu ) {
2175+ let viewModeEnabled = actionResult ?. appState ?. viewModeEnabled || false ;
2176+ let zenModeEnabled = actionResult ?. appState ?. zenModeEnabled || false ;
2177+ let gridSize = actionResult ?. appState ?. gridSize || null ;
2178+ const theme =
2179+ actionResult ?. appState ?. theme || this . props . theme || THEME . LIGHT ;
2180+ const name = actionResult ?. appState ?. name ?? this . state . name ;
2181+ const errorMessage =
2182+ actionResult ?. appState ?. errorMessage ?? this . state . errorMessage ;
2183+ if ( typeof this . props . viewModeEnabled !== "undefined" ) {
2184+ viewModeEnabled = this . props . viewModeEnabled ;
21702185 }
21712186
2172- if ( actionResult . appState || editingElement || this . state . contextMenu ) {
2173- if ( actionResult . storeAction === StoreAction . UPDATE ) {
2174- this . store . shouldUpdateSnapshot ( ) ;
2175- } else if ( actionResult . storeAction === StoreAction . CAPTURE ) {
2176- this . store . shouldCaptureIncrement ( ) ;
2177- }
2187+ if ( typeof this . props . zenModeEnabled !== "undefined" ) {
2188+ zenModeEnabled = this . props . zenModeEnabled ;
2189+ }
21782190
2179- let viewModeEnabled = actionResult ?. appState ?. viewModeEnabled || false ;
2180- let zenModeEnabled = actionResult ?. appState ?. zenModeEnabled || false ;
2181- let gridSize = actionResult ?. appState ?. gridSize || null ;
2182- const theme =
2183- actionResult ?. appState ?. theme || this . props . theme || THEME . LIGHT ;
2184- const name = actionResult ?. appState ?. name ?? this . state . name ;
2185- const errorMessage =
2186- actionResult ?. appState ?. errorMessage ?? this . state . errorMessage ;
2187- if ( typeof this . props . viewModeEnabled !== "undefined" ) {
2188- viewModeEnabled = this . props . viewModeEnabled ;
2189- }
2191+ if ( typeof this . props . gridModeEnabled !== "undefined" ) {
2192+ gridSize = this . props . gridModeEnabled ? GRID_SIZE : null ;
2193+ }
21902194
2191- if ( typeof this . props . zenModeEnabled !== "undefined" ) {
2192- zenModeEnabled = this . props . zenModeEnabled ;
2193- }
2195+ editingElement =
2196+ editingElement || actionResult . appState ?. editingElement || null ;
21942197
2195- if ( typeof this . props . gridModeEnabled !== "undefined" ) {
2196- gridSize = this . props . gridModeEnabled ? GRID_SIZE : null ;
2197- }
2198+ if ( editingElement ?. isDeleted ) {
2199+ editingElement = null ;
2200+ }
21982201
2199- editingElement =
2200- editingElement || actionResult . appState ?. editingElement || null ;
2202+ this . setState ( ( state ) => {
2203+ // using Object.assign instead of spread to fool TS 4.2.2+ into
2204+ // regarding the resulting type as not containing undefined
2205+ // (which the following expression will never contain)
2206+ return Object . assign ( actionResult . appState || { } , {
2207+ // NOTE this will prevent opening context menu using an action
2208+ // or programmatically from the host, so it will need to be
2209+ // rewritten later
2210+ contextMenu : null ,
2211+ editingElement,
2212+ viewModeEnabled,
2213+ zenModeEnabled,
2214+ gridSize,
2215+ theme,
2216+ name,
2217+ errorMessage,
2218+ } ) ;
2219+ } ) ;
22012220
2202- if ( editingElement ?. isDeleted ) {
2203- editingElement = null ;
2204- }
2221+ didUpdate = true ;
2222+ }
22052223
2206- this . setState ( ( state ) => {
2207- // using Object.assign instead of spread to fool TS 4.2.2+ into
2208- // regarding the resulting type as not containing undefined
2209- // (which the following expression will never contain)
2210- return Object . assign ( actionResult . appState || { } , {
2211- // NOTE this will prevent opening context menu using an action
2212- // or programmatically from the host, so it will need to be
2213- // rewritten later
2214- contextMenu : null ,
2215- editingElement,
2216- viewModeEnabled,
2217- zenModeEnabled,
2218- gridSize,
2219- theme,
2220- name,
2221- errorMessage,
2222- } ) ;
2223- } ) ;
2224- }
2225- } ,
2226- ) ;
2224+ if ( ! didUpdate && actionResult . storeAction !== StoreAction . NONE ) {
2225+ this . scene . triggerUpdate ( ) ;
2226+ }
2227+ } ) ;
22272228
22282229 // Lifecycle
22292230
0 commit comments