@ -24,7 +24,7 @@
import koArray , { KoArray } from 'app/client/lib/koArray' ;
import koArray , { KoArray } from 'app/client/lib/koArray' ;
import { DisposableWithEvents } from 'app/common/DisposableWithEvents' ;
import { DisposableWithEvents } from 'app/common/DisposableWithEvents' ;
import { CompareFunc , sortedIndex } from 'app/common/gutil' ;
import { CompareFunc , sortedIndex } from 'app/common/gutil' ;
import { SkippableRows } from 'app/common/TableData' ;
import { SkippableRows , UIRowId } from 'app/common/TableData' ;
import { RowFilterFunc } from "app/common/RowFilterFunc" ;
import { RowFilterFunc } from "app/common/RowFilterFunc" ;
import { Observable } from 'grainjs' ;
import { Observable } from 'grainjs' ;
@ -36,8 +36,7 @@ export const ALL: unique symbol = Symbol("ALL");
export type ChangeType = 'add' | 'remove' | 'update' ;
export type ChangeType = 'add' | 'remove' | 'update' ;
export type ChangeMethod = 'onAddRows' | 'onRemoveRows' | 'onUpdateRows' ;
export type ChangeMethod = 'onAddRows' | 'onRemoveRows' | 'onUpdateRows' ;
export type RowId = number | 'new' ;
export type RowList = Iterable < UIRowId > ;
export type RowList = Iterable < RowId > ;
export type RowsChanged = RowList | typeof ALL ;
export type RowsChanged = RowList | typeof ALL ;
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
@ -132,7 +131,7 @@ export class RowListener extends DisposableWithEvents {
* A trivial RowSource returning a fixed list of rows .
* A trivial RowSource returning a fixed list of rows .
* /
* /
export abstract class ArrayRowSource extends RowSource {
export abstract class ArrayRowSource extends RowSource {
constructor ( private _rows : RowId[ ] ) { super ( ) ; }
constructor ( private _rows : UI RowId[ ] ) { super ( ) ; }
public getAllRows ( ) : RowList { return this . _rows ; }
public getAllRows ( ) : RowList { return this . _rows ; }
public getNumRows ( ) : number { return this . _rows . length ; }
public getNumRows ( ) : number { return this . _rows . length ; }
}
}
@ -146,11 +145,11 @@ export abstract class ArrayRowSource extends RowSource {
* TODO : This class is not used anywhere at the moment , and is a candidate for removal .
* TODO : This class is not used anywhere at the moment , and is a candidate for removal .
* /
* /
export class MappedRowSource extends RowSource {
export class MappedRowSource extends RowSource {
private _mapperFunc : ( row : RowId) = > RowId;
private _mapperFunc : ( row : UI RowId) = > UI RowId;
constructor (
constructor (
public parentRowSource : RowSource ,
public parentRowSource : RowSource ,
mapperFunc : ( row : RowId) = > RowId,
mapperFunc : ( row : UI RowId) = > UI RowId,
) {
) {
super ( ) ;
super ( ) ;
@ -182,7 +181,7 @@ export class ExtendedRowSource extends RowSource {
constructor (
constructor (
public parentRowSource : RowSource ,
public parentRowSource : RowSource ,
public extras : RowId[ ]
public extras : UI RowId[ ]
) {
) {
super ( ) ;
super ( ) ;
@ -209,9 +208,9 @@ export class ExtendedRowSource extends RowSource {
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
interface FilterRowChanges {
interface FilterRowChanges {
adds? : RowId[ ] ;
adds? : UI RowId[ ] ;
updates? : RowId[ ] ;
updates? : UI RowId[ ] ;
removes? : RowId[ ] ;
removes? : UI RowId[ ] ;
}
}
/ * *
/ * *
@ -219,9 +218,9 @@ interface FilterRowChanges {
* does not maintain excluded rows , and does not allow changes to filterFunc .
* does not maintain excluded rows , and does not allow changes to filterFunc .
* /
* /
export class BaseFilteredRowSource extends RowListener implements RowSource {
export class BaseFilteredRowSource extends RowListener implements RowSource {
protected _matchingRows : Set < RowId> = new Set ( ) ; // Set of rows matching the filter.
protected _matchingRows : Set < UI RowId> = new Set ( ) ; // Set of rows matching the filter.
constructor ( protected _filterFunc : RowFilterFunc < RowId> ) {
constructor ( protected _filterFunc : RowFilterFunc < UI RowId> ) {
super ( ) ;
super ( ) ;
}
}
@ -309,8 +308,8 @@ export class BaseFilteredRowSource extends RowListener implements RowSource {
}
}
// These are implemented by FilteredRowSource, but the base class doesn't need to do anything.
// These are implemented by FilteredRowSource, but the base class doesn't need to do anything.
protected _addExcludedRow ( row : RowId) : void { /* no-op */ }
protected _addExcludedRow ( row : UI RowId) : void { /* no-op */ }
protected _deleteExcludedRow ( row : RowId) : boolean { return true ; }
protected _deleteExcludedRow ( row : UI RowId) : boolean { return true ; }
}
}
/ * *
/ * *
@ -321,13 +320,13 @@ export class BaseFilteredRowSource extends RowListener implements RowSource {
* FilteredRowSource is also a RowListener , so to subscribe to a rowSource , use ` subscribeTo() ` .
* FilteredRowSource is also a RowListener , so to subscribe to a rowSource , use ` subscribeTo() ` .
* /
* /
export class FilteredRowSource extends BaseFilteredRowSource {
export class FilteredRowSource extends BaseFilteredRowSource {
private _excludedRows : Set < RowId> = new Set ( ) ; // Set of rows NOT matching the filter.
private _excludedRows : Set < UI RowId> = new Set ( ) ; // Set of rows NOT matching the filter.
/ * *
/ * *
* Change the filter function . This may trigger 'remove' and 'add' events as necessary to indicate
* Change the filter function . This may trigger 'remove' and 'add' events as necessary to indicate
* that rows stopped or started matching the new filter .
* that rows stopped or started matching the new filter .
* /
* /
public updateFilter ( filterFunc : RowFilterFunc < RowId> ) {
public updateFilter ( filterFunc : RowFilterFunc < UI RowId> ) {
this . _filterFunc = filterFunc ;
this . _filterFunc = filterFunc ;
const changes : FilterRowChanges = { } ;
const changes : FilterRowChanges = { } ;
// After the first call, _excludedRows may have additional rows, but there is no harm in it,
// After the first call, _excludedRows may have additional rows, but there is no harm in it,
@ -356,8 +355,8 @@ export class FilteredRowSource extends BaseFilteredRowSource {
return this . _excludedRows . values ( ) ;
return this . _excludedRows . values ( ) ;
}
}
protected _addExcludedRow ( row : RowId) : void { this . _excludedRows . add ( row ) ; }
protected _addExcludedRow ( row : UI RowId) : void { this . _excludedRows . add ( row ) ; }
protected _deleteExcludedRow ( row : RowId) : boolean { return this . _excludedRows . delete ( row ) ; }
protected _deleteExcludedRow ( row : UI RowId) : boolean { return this . _excludedRows . delete ( row ) ; }
}
}
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
@ -368,7 +367,7 @@ export class FilteredRowSource extends BaseFilteredRowSource {
* Private helper object that maintains a set of rows for a particular group .
* Private helper object that maintains a set of rows for a particular group .
* /
* /
class RowGroupHelper < Value > extends RowSource {
class RowGroupHelper < Value > extends RowSource {
private _rows : Set < RowId> = new Set ( ) ;
private _rows : Set < UI RowId> = new Set ( ) ;
constructor ( public readonly groupValue : Value ) {
constructor ( public readonly groupValue : Value ) {
super ( ) ;
super ( ) ;
}
}
@ -411,12 +410,12 @@ function _addToMapOfArrays<K, V>(map: Map<K, V[]>, key: K, r: V): void {
* /
* /
export class RowGrouping < Value > extends RowListener {
export class RowGrouping < Value > extends RowListener {
// Maps row identifiers to groupValues.
// Maps row identifiers to groupValues.
private _rowsToValues : Map < RowId, Value > = new Map ( ) ;
private _rowsToValues : Map < UI RowId, Value > = new Map ( ) ;
// Maps group values to RowGroupHelpers
// Maps group values to RowGroupHelpers
private _valuesToGroups : Map < Value , RowGroupHelper < Value > > = new Map ( ) ;
private _valuesToGroups : Map < Value , RowGroupHelper < Value > > = new Map ( ) ;
constructor ( private _groupFunc : ( row : RowId) = > Value ) {
constructor ( private _groupFunc : ( row : UI RowId) = > Value ) {
super ( ) ;
super ( ) ;
// On disposal, dispose all RowGroupHelpers that we maintain.
// On disposal, dispose all RowGroupHelpers that we maintain.
@ -538,15 +537,15 @@ export class RowGrouping<Value> extends RowListener {
* SortedRowSet re - emits 'rowNotify(rows, value)' events from RowSources that it subscribes to .
* SortedRowSet re - emits 'rowNotify(rows, value)' events from RowSources that it subscribes to .
* /
* /
export class SortedRowSet extends RowListener {
export class SortedRowSet extends RowListener {
private _allRows : Set < RowId> = new Set ( ) ;
private _allRows : Set < UI RowId> = new Set ( ) ;
private _isPaused : boolean = false ;
private _isPaused : boolean = false ;
private _koArray : KoArray < RowId> ;
private _koArray : KoArray < UI RowId> ;
private _keepFunc ? : ( rowId : number | 'new' ) = > boolean ;
private _keepFunc ? : ( rowId : number | 'new' ) = > boolean ;
constructor ( private _compareFunc : CompareFunc < RowId> ,
constructor ( private _compareFunc : CompareFunc < UI RowId> ,
private _skippableRows? : SkippableRows ) {
private _skippableRows? : SkippableRows ) {
super ( ) ;
super ( ) ;
this . _koArray = this . autoDispose ( koArray < RowId> ( ) ) ;
this . _koArray = this . autoDispose ( koArray < UI RowId> ( ) ) ;
this . _keepFunc = _skippableRows ? . getKeepFunc ( ) ;
this . _keepFunc = _skippableRows ? . getKeepFunc ( ) ;
}
}
@ -572,7 +571,7 @@ export class SortedRowSet extends RowListener {
/ * *
/ * *
* Re - sorts the array according to the new compareFunc .
* Re - sorts the array according to the new compareFunc .
* /
* /
public updateSort ( compareFunc : CompareFunc < RowId> ) : void {
public updateSort ( compareFunc : CompareFunc < UI RowId> ) : void {
this . _compareFunc = compareFunc ;
this . _compareFunc = compareFunc ;
if ( ! this . _isPaused ) {
if ( ! this . _isPaused ) {
this . _koArray . assign ( Array . from ( this . _koArray . peek ( ) ) . sort ( this . _compareFunc ) ) ;
this . _koArray . assign ( Array . from ( this . _koArray . peek ( ) ) . sort ( this . _compareFunc ) ) ;
@ -650,7 +649,7 @@ export class SortedRowSet extends RowListener {
// Filter out any rows that should be skipped. This is a no-op if no _keepFunc was found.
// Filter out any rows that should be skipped. This is a no-op if no _keepFunc was found.
// All rows that sort within nContext rows of something meant to be kept are also kept.
// All rows that sort within nContext rows of something meant to be kept are also kept.
private _keep ( rows : RowId[ ] , nContext : number = 2 ) {
private _keep ( rows : UI RowId[ ] , nContext : number = 2 ) {
// Nothing to be done if there's no _keepFunc.
// Nothing to be done if there's no _keepFunc.
if ( ! this . _keepFunc ) { return rows ; }
if ( ! this . _keepFunc ) { return rows ; }
@ -706,7 +705,7 @@ export class SortedRowSet extends RowListener {
}
}
}
}
type RowTester = ( rowId : RowId) = > boolean ;
type RowTester = ( rowId : UI RowId) = > boolean ;
/ * *
/ * *
* RowWatcher is a RowListener that maintains an observable function that checks whether a row
* RowWatcher is a RowListener that maintains an observable function that checks whether a row
* is in the connected RowSource .
* is in the connected RowSource .
@ -718,7 +717,7 @@ export class RowWatcher extends RowListener {
public rowFilter : Observable < RowTester > = Observable . create ( this , ( ) = > false ) ;
public rowFilter : Observable < RowTester > = Observable . create ( this , ( ) = > false ) ;
// We count the number of times the row is added or removed from the source.
// We count the number of times the row is added or removed from the source.
// In most cases row is added and removed only once.
// In most cases row is added and removed only once.
private _rowCounter : Map < RowId, number > = new Map ( ) ;
private _rowCounter : Map < UI RowId, number > = new Map ( ) ;
public clear() {
public clear() {
this . _rowCounter . clear ( ) ;
this . _rowCounter . clear ( ) ;