1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | "use strict";
|
8 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
9 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
10 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
11 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
12 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
13 | };
|
14 | var __metadata = (this && this.__metadata) || function (k, v) {
|
15 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
16 | };
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | var context_1 = require("../../context/context");
|
19 | var constants_1 = require("../../constants");
|
20 | var utils_1 = require("../../utils");
|
21 | var gridOptionsWrapper_1 = require("../../gridOptionsWrapper");
|
22 | var ImmutableService = (function () {
|
23 | function ImmutableService() {
|
24 | }
|
25 | ImmutableService.prototype.postConstruct = function () {
|
26 | if (this.rowModel.getType() === constants_1.Constants.ROW_MODEL_TYPE_CLIENT_SIDE) {
|
27 | this.clientSideRowModel = this.rowModel;
|
28 | }
|
29 | };
|
30 |
|
31 | ImmutableService.prototype.createTransactionForRowData = function (data) {
|
32 | if (utils_1._.missing(this.clientSideRowModel)) {
|
33 | console.error('ag-Grid: ImmutableService only works with ClientSideRowModel');
|
34 | return;
|
35 | }
|
36 | var getRowNodeIdFunc = this.gridOptionsWrapper.getRowNodeIdFunc();
|
37 | if (utils_1._.missing(getRowNodeIdFunc)) {
|
38 | console.error('ag-Grid: ImmutableService requires getRowNodeId() callback to be implemented, your row data need IDs!');
|
39 | return;
|
40 | }
|
41 |
|
42 | var transaction = {
|
43 | remove: [],
|
44 | update: [],
|
45 | add: []
|
46 | };
|
47 | var existingNodesMap = this.clientSideRowModel.getCopyOfNodesMap();
|
48 | var orderMap = {};
|
49 | if (utils_1._.exists(data)) {
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | data.forEach(function (dataItem, index) {
|
55 | var id = getRowNodeIdFunc(dataItem);
|
56 | var existingNode = existingNodesMap[id];
|
57 | orderMap[id] = index;
|
58 | if (existingNode) {
|
59 | var dataHasChanged = existingNode.data !== dataItem;
|
60 | if (dataHasChanged) {
|
61 | transaction.update.push(dataItem);
|
62 | }
|
63 |
|
64 |
|
65 | existingNodesMap[id] = undefined;
|
66 | }
|
67 | else {
|
68 | transaction.add.push(dataItem);
|
69 | }
|
70 | });
|
71 | }
|
72 |
|
73 | utils_1._.iterateObject(existingNodesMap, function (id, rowNode) {
|
74 | if (rowNode) {
|
75 | transaction.remove.push(rowNode.data);
|
76 | }
|
77 | });
|
78 | return [transaction, orderMap];
|
79 | };
|
80 | __decorate([
|
81 | context_1.Autowired('rowModel'),
|
82 | __metadata("design:type", Object)
|
83 | ], ImmutableService.prototype, "rowModel", void 0);
|
84 | __decorate([
|
85 | context_1.Autowired('gridOptionsWrapper'),
|
86 | __metadata("design:type", gridOptionsWrapper_1.GridOptionsWrapper)
|
87 | ], ImmutableService.prototype, "gridOptionsWrapper", void 0);
|
88 | __decorate([
|
89 | context_1.PostConstruct,
|
90 | __metadata("design:type", Function),
|
91 | __metadata("design:paramtypes", []),
|
92 | __metadata("design:returntype", void 0)
|
93 | ], ImmutableService.prototype, "postConstruct", null);
|
94 | ImmutableService = __decorate([
|
95 | context_1.Bean('immutableService')
|
96 | ], ImmutableService);
|
97 | return ImmutableService;
|
98 | }());
|
99 | exports.ImmutableService = ImmutableService;
|