@@ -176,6 +176,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
176176 willSetValues ?: ( values : Values ) => Values | undefined ,
177177 willDelRow ?: ( tableId : Id , rowId : Id ) => boolean ,
178178 willDelValues ?: ( ) => boolean ,
179+ willSetTable ?: ( tableId : Id , table : Table ) => Table | undefined ,
179180 ] = [ ] ;
180181 let internalListeners : [
181182 preStartTransaction ?: ( ) => void ,
@@ -471,18 +472,34 @@ export const createStore: typeof createStoreDecl = (): Store => {
471472 ( _tables , tableId ) => delValidTable ( tableId ) ,
472473 ) ;
473474
474- const setValidTable = ( tableId : Id , table : Table ) : TableMap =>
475- mapMatch (
476- mapEnsure ( tablesMap , tableId , ( ) => {
477- tableIdsChanged ( tableId , 1 ) ;
478- mapSet ( tablePoolFunctions , tableId , getPoolFunctions ( ) ) ;
479- mapSet ( tableCellIds , tableId , mapNew ( ) ) ;
480- return mapNew ( ) ;
481- } ) ,
482- table ,
483- ( tableMap , rowId , row ) => setValidRow ( tableId , tableMap , rowId , row ) ,
484- ( tableMap , rowId ) => delValidRow ( tableId , tableMap , rowId ) ,
485- ) ;
475+ const setValidTable = (
476+ tableId : Id ,
477+ table : Table ,
478+ forceDel ?: boolean ,
479+ ) : TableMap =>
480+ ifNotUndefined (
481+ forceDel
482+ ? table
483+ : ifNotUndefined (
484+ internalWillSets [ 8 ] ,
485+ ( willSetTable ) => willSetTable ( tableId , table ) ,
486+ ( ) => table ,
487+ ) ,
488+ ( validTable ) =>
489+ mapMatch (
490+ mapEnsure ( tablesMap , tableId , ( ) => {
491+ tableIdsChanged ( tableId , 1 ) ;
492+ mapSet ( tablePoolFunctions , tableId , getPoolFunctions ( ) ) ;
493+ mapSet ( tableCellIds , tableId , mapNew ( ) ) ;
494+ return mapNew ( ) ;
495+ } ) ,
496+ validTable ,
497+ ( tableMap , rowId , row ) =>
498+ setValidRow ( tableId , tableMap , rowId , row ) ,
499+ ( tableMap , rowId ) =>
500+ delValidRow ( tableId , tableMap , rowId ) ,
501+ ) ,
502+ ) as TableMap ;
486503
487504 const setValidRow = (
488505 tableId : Id ,
@@ -612,7 +629,8 @@ export const createStore: typeof createStoreDecl = (): Store => {
612629 const getOrCreateTable = ( tableId : Id ) =>
613630 mapGet ( tablesMap , tableId ) ?? setValidTable ( tableId , { } ) ;
614631
615- const delValidTable = ( tableId : Id ) : TableMap => setValidTable ( tableId , { } ) ;
632+ const delValidTable = ( tableId : Id ) : TableMap =>
633+ setValidTable ( tableId , { } , true ) ;
616634
617635 const delValidRow = ( tableId : Id , tableMap : TableMap , rowId : Id ) : void => {
618636 if ( internalWillSets [ 6 ] ?.( tableId , rowId ) ?? true ) {
@@ -1783,6 +1801,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
17831801 willSetValues : ( values : Values ) => Values | undefined ,
17841802 willDelRow : ( tableId : Id , rowId : Id ) => boolean ,
17851803 willDelValues : ( ) => boolean ,
1804+ willSetTable : ( tableId : Id , table : Table ) => Table | undefined ,
17861805 ) =>
17871806 ( internalWillSets = [
17881807 willSetCell ,
@@ -1793,6 +1812,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
17931812 willSetValues ,
17941813 willDelRow ,
17951814 willDelValues ,
1815+ willSetTable ,
17961816 ] ) ;
17971817
17981818 const setInternalListeners = (
0 commit comments