UNPKG

2.2 kBPlain TextView Raw
1
2import {Column} from "../entities/column";
3import {RowNode} from "../entities/rowNode";
4import {Autowired, Bean, PostConstruct} from "../context/context";
5import {GridOptionsWrapper} from "../gridOptionsWrapper";
6import {ChangedPath} from "../rowModels/clientSide/changedPath";
7import {IRowModel} from "../interfaces/iRowModel";
8import {ClientSideRowModel} from "../rowModels/clientSide/clientSideRowModel";
9import {RowRenderer} from "../rendering/rowRenderer";
10import {EventService} from "../eventService";
11import {Constants} from "../constants";
12import {BeanStub} from "../context/beanStub";
13import {Events} from "../events";
14
15@Bean('changeDetectionService')
16export class ChangeDetectionService extends BeanStub {
17
18 @Autowired('gridOptionsWrapper') private gridOptionsWrapper: GridOptionsWrapper;
19 @Autowired('rowModel') private rowModel: IRowModel;
20 @Autowired('rowRenderer') private rowRenderer: RowRenderer;
21 @Autowired('eventService') private eventService: EventService;
22
23 private clientSideRowModel: ClientSideRowModel;
24
25 @PostConstruct
26 private init(): void {
27 if (this.rowModel.getType()===Constants.ROW_MODEL_TYPE_CLIENT_SIDE) {
28 this.clientSideRowModel = <ClientSideRowModel> this.rowModel;
29 }
30
31 this.addDestroyableEventListener(this.eventService, Events.EVENT_CELL_VALUE_CHANGED, this.onCellValueChanged.bind(this));
32 }
33
34 private onCellValueChanged(event: any): void {
35 this.doChangeDetection(event.node, event.column);
36 }
37
38 private doChangeDetection(rowNode: RowNode, column: Column): void {
39 if (this.gridOptionsWrapper.isSuppressChangeDetection()) { return; }
40
41 // step 1 of change detection is to update the aggregated values
42 if (this.clientSideRowModel && !rowNode.isRowPinned()) {
43 let onlyChangedColumns = this.gridOptionsWrapper.isAggregateOnlyChangedColumns();
44 let changedPath = new ChangedPath(onlyChangedColumns);
45 changedPath.addParentNode(rowNode.parent, [column]);
46 this.clientSideRowModel.doAggregate(changedPath);
47 }
48
49 // step 2 of change detection is to refresh the cells
50 this.rowRenderer.refreshCells();
51 }
52
53}
\No newline at end of file