@@ -44,11 +44,7 @@ import {
4444 arrayPush ,
4545 arraySort ,
4646} from '../common/array.ts' ;
47- import {
48- getCellOrValueType ,
49- setOrDelCell ,
50- setOrDelValue ,
51- } from '../common/cell.ts' ;
47+ import { getCellOrValueType } from '../common/cell.ts' ;
5248import {
5349 collClear ,
5450 collDel ,
@@ -466,6 +462,29 @@ export const createStore: typeof createStoreDecl = (): Store => {
466462 const setOrDelTables = ( tables : Tables ) =>
467463 objIsEmpty ( tables ) ? delTables ( ) : setTables ( tables ) ;
468464
465+ const setOrDelCell = (
466+ tableId : Id ,
467+ rowId : Id ,
468+ cellId : Id ,
469+ cell : CellOrUndefined ,
470+ skipWillCallbacks ?: boolean ,
471+ ) =>
472+ isUndefined ( cell )
473+ ? delCell ( tableId , rowId , cellId , true , skipWillCallbacks )
474+ : setCell ( tableId , rowId , cellId , cell , skipWillCallbacks ) ;
475+
476+ const setOrDelValues = ( values : Values ) =>
477+ objIsEmpty ( values ) ? delValues ( ) : setValues ( values ) ;
478+
479+ const setOrDelValue = (
480+ valueId : Id ,
481+ value : ValueOrUndefined ,
482+ skipWillCallbacks ?: boolean ,
483+ ) =>
484+ isUndefined ( value )
485+ ? delValue ( valueId , skipWillCallbacks )
486+ : setValue ( valueId , value , skipWillCallbacks ) ;
487+
469488 const setValidContent = ( content : Content ) : void =>
470489 ifNotUndefined (
471490 ifNotUndefined (
@@ -559,10 +578,11 @@ export const createStore: typeof createStoreDecl = (): Store => {
559578 rowMap : RowMap ,
560579 cellId : Id ,
561580 cell : Cell ,
581+ skipWillCallbacks ?: boolean ,
562582 ) : void =>
563583 ifNotUndefined (
564584 ifNotUndefined (
565- willCallbacks [ 4 ] ,
585+ skipWillCallbacks ? undefined : willCallbacks [ 4 ] ,
566586 ( willSetCell ) => willSetCell ( tableId , rowId , cellId , cell ) ,
567587 ( ) => cell ,
568588 ) ,
@@ -584,25 +604,38 @@ export const createStore: typeof createStoreDecl = (): Store => {
584604 rowId : Id ,
585605 cellId : Id ,
586606 validCell : Cell ,
607+ skipWillCallbacks ?: boolean ,
587608 ) : void =>
588609 ifNotUndefined (
589610 mapGet ( tableMap , rowId ) ,
590- ( rowMap ) : any => setValidCell ( tableId , rowId , rowMap , cellId , validCell ) ,
611+ ( rowMap ) : any =>
612+ setValidCell (
613+ tableId ,
614+ rowId ,
615+ rowMap ,
616+ cellId ,
617+ validCell ,
618+ skipWillCallbacks ,
619+ ) ,
591620 ( ) => {
592621 const rowMap : RowMap = mapNew ( ) ;
593622 mapSet ( tableMap , rowId , rowMap ) ;
594623 rowIdsChanged ( tableId , rowId , 1 ) ;
595624 objMap (
596625 addDefaultsToRow ( { [ cellId ] : validCell } , tableId , rowId ) ,
597626 ( cell , cellId ) =>
598- setValidCell ( tableId , rowId , rowMap , cellId , cell as Cell ) ,
627+ setValidCell (
628+ tableId ,
629+ rowId ,
630+ rowMap ,
631+ cellId ,
632+ cell as Cell ,
633+ skipWillCallbacks ,
634+ ) ,
599635 ) ;
600636 } ,
601637 ) ;
602638
603- const setOrDelValues = ( values : Values ) =>
604- objIsEmpty ( values ) ? delValues ( ) : setValues ( values ) ;
605-
606639 const setValidValues = (
607640 values : Values ,
608641 forceDel ?: boolean ,
@@ -624,10 +657,14 @@ export const createStore: typeof createStoreDecl = (): Store => {
624657 ) ,
625658 ) ;
626659
627- const setValidValue = ( valueId : Id , value : Value ) : void =>
660+ const setValidValue = (
661+ valueId : Id ,
662+ value : Value ,
663+ skipWillCallbacks ?: boolean ,
664+ ) : void =>
628665 ifNotUndefined (
629666 ifNotUndefined (
630- willCallbacks [ 6 ] ,
667+ skipWillCallbacks ? undefined : willCallbacks [ 6 ] ,
631668 ( willSetValue ) => willSetValue ( valueId , value ) ,
632669 ( ) => value ,
633670 ) ,
@@ -680,6 +717,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
680717 row : RowMap ,
681718 cellId : Id ,
682719 forceDel ?: boolean ,
720+ skipWillCallbacks ?: boolean ,
683721 ) : void => {
684722 const defaultCell = mapGet (
685723 mapGet ( tablesSchemaRowCache , tableId ) ?. [ 0 ] ,
@@ -688,7 +726,10 @@ export const createStore: typeof createStoreDecl = (): Store => {
688726 if ( ! isUndefined ( defaultCell ) && ! forceDel ) {
689727 return setValidCell ( tableId , rowId , row , cellId , defaultCell ) ;
690728 }
691- if ( willCallbacks [ 10 ] ?.( tableId , rowId , cellId ) ?? true ) {
729+ if (
730+ skipWillCallbacks ||
731+ ( willCallbacks [ 10 ] ?.( tableId , rowId , cellId ) ?? true )
732+ ) {
692733 const delCell = ( cellId : Id ) => {
693734 cellChanged ( tableId , rowId , cellId , mapGet ( row , cellId ) ) ;
694735 cellIdsChanged ( tableId , rowId , cellId , - 1 ) ;
@@ -711,12 +752,12 @@ export const createStore: typeof createStoreDecl = (): Store => {
711752 }
712753 } ;
713754
714- const delValidValue = ( valueId : Id ) : void => {
755+ const delValidValue = ( valueId : Id , skipWillCallbacks ?: boolean ) : void => {
715756 const defaultValue = mapGet ( valuesDefaulted , valueId ) ;
716757 if ( ! isUndefined ( defaultValue ) ) {
717758 return setValidValue ( valueId , defaultValue ) ;
718759 }
719- if ( willCallbacks [ 12 ] ?.( valueId ) ?? true ) {
760+ if ( skipWillCallbacks || ( willCallbacks [ 12 ] ?.( valueId ) ?? true ) ) {
720761 valueChanged ( valueId , mapGet ( valuesMap , valueId ) ) ;
721762 valueIdsChanged ( valueId , - 1 ) ;
722763 mapSet ( valuesMap , valueId ) ;
@@ -1328,6 +1369,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
13281369 rowId : Id ,
13291370 cellId : Id ,
13301371 cell : Cell | MapCell ,
1372+ skipWillCallbacks ?: boolean ,
13311373 ) : Store =>
13321374 fluentTransaction (
13331375 ( tableId , rowId , cellId ) =>
@@ -1345,6 +1387,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
13451387 rowId ,
13461388 cellId ,
13471389 validCell ,
1390+ skipWillCallbacks ,
13481391 ) ,
13491392 ) ,
13501393 tableId ,
@@ -1366,15 +1409,19 @@ export const createStore: typeof createStoreDecl = (): Store => {
13661409 : 0 ,
13671410 ) ;
13681411
1369- const setValue = ( valueId : Id , value : Value ) : Store =>
1412+ const setValue = (
1413+ valueId : Id ,
1414+ value : Value ,
1415+ skipWillCallbacks ?: boolean ,
1416+ ) : Store =>
13701417 fluentTransaction (
13711418 ( valueId ) =>
13721419 ifNotUndefined (
13731420 getValidatedValue (
13741421 valueId ,
13751422 isFunction ( value ) ? value ( getValue ( valueId ) ) : value ,
13761423 ) ,
1377- ( validValue ) => setValidValue ( valueId , validValue ) ,
1424+ ( validValue ) => setValidValue ( valueId , validValue , skipWillCallbacks ) ,
13781425 ) ,
13791426 valueId ,
13801427 ) ;
@@ -1396,7 +1443,6 @@ export const createStore: typeof createStoreDecl = (): Store => {
13961443 ? delRow ( tableId , rowId )
13971444 : objMap ( row , ( cell , cellId ) =>
13981445 setOrDelCell (
1399- store ,
14001446 tableId ,
14011447 rowId ,
14021448 cellId ,
@@ -1406,7 +1452,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
14061452 ) ,
14071453 ) ;
14081454 objMap ( changes [ 1 ] , ( value , valueId ) =>
1409- setOrDelValue ( store , valueId , value as ValueOrUndefined ) ,
1455+ setOrDelValue ( valueId , value as ValueOrUndefined ) ,
14101456 ) ;
14111457 } ,
14121458 ) ,
@@ -1493,13 +1539,22 @@ export const createStore: typeof createStoreDecl = (): Store => {
14931539 rowId : Id ,
14941540 cellId : Id ,
14951541 forceDel ?: boolean ,
1542+ skipWillCallbacks ?: boolean ,
14961543 ) : Store =>
14971544 fluentTransaction (
14981545 ( tableId , rowId , cellId ) =>
14991546 ifNotUndefined ( mapGet ( tablesMap , tableId ) , ( tableMap ) =>
15001547 ifNotUndefined ( mapGet ( tableMap , rowId ) , ( rowMap ) =>
15011548 collHas ( rowMap , cellId )
1502- ? delValidCell ( tableId , tableMap , rowId , rowMap , cellId , forceDel )
1549+ ? delValidCell (
1550+ tableId ,
1551+ tableMap ,
1552+ rowId ,
1553+ rowMap ,
1554+ cellId ,
1555+ forceDel ,
1556+ skipWillCallbacks ,
1557+ )
15031558 : 0 ,
15041559 ) ,
15051560 ) ,
@@ -1513,9 +1568,12 @@ export const createStore: typeof createStoreDecl = (): Store => {
15131568 ( willCallbacks [ 11 ] ?.( ) ?? true ) ? setValidValues ( { } , true ) : 0 ,
15141569 ) ;
15151570
1516- const delValue = ( valueId : Id ) : Store =>
1571+ const delValue = ( valueId : Id , skipWillCallbacks ?: boolean ) : Store =>
15171572 fluentTransaction (
1518- ( valueId ) => ( collHas ( valuesMap , valueId ) ? delValidValue ( valueId ) : 0 ) ,
1573+ ( valueId ) =>
1574+ collHas ( valuesMap , valueId )
1575+ ? delValidValue ( valueId , skipWillCallbacks )
1576+ : 0 ,
15191577 valueId ,
15201578 ) ;
15211579
@@ -1627,13 +1685,13 @@ export const createStore: typeof createStoreDecl = (): Store => {
16271685 collForEach ( changedCells , ( table , tableId ) =>
16281686 collForEach ( table , ( row , rowId ) =>
16291687 collForEach ( row , ( [ oldCell ] , cellId ) =>
1630- setOrDelCell ( store , tableId , rowId , cellId , oldCell ) ,
1688+ setOrDelCell ( tableId , rowId , cellId , oldCell , true ) ,
16311689 ) ,
16321690 ) ,
16331691 ) ;
16341692 collClear ( changedCells ) ;
16351693 collForEach ( changedValues , ( [ oldValue ] , valueId ) =>
1636- setOrDelValue ( store , valueId , oldValue ) ,
1694+ setOrDelValue ( valueId , oldValue , true ) ,
16371695 ) ;
16381696 collClear ( changedValues ) ;
16391697 }
@@ -1940,6 +1998,8 @@ export const createStore: typeof createStoreDecl = (): Store => {
19401998 callListeners,
19411999 setInternalListeners,
19422000 setWillCallbacks,
2001+ setOrDelCell,
2002+ setOrDelValue,
19432003 } ;
19442004
19452005 // and now for some gentle meta-programming
0 commit comments