UNPKG

4.44 kBJavaScriptView Raw
1/**
2 * ag-grid - Advanced Data Grid / Data Table supporting Javascript / React / AngularJS / Web Components
3 * @version v18.1.2
4 * @link http://www.ag-grid.com/
5 * @license MIT
6 */
7"use strict";
8var __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};
14var __metadata = (this && this.__metadata) || function (k, v) {
15 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
16};
17var __param = (this && this.__param) || function (paramIndex, decorator) {
18 return function (target, key) { decorator(target, key, paramIndex); }
19};
20Object.defineProperty(exports, "__esModule", { value: true });
21var rowNodeBlock_1 = require("./rowNodeBlock");
22var logger_1 = require("../../logger");
23var context_1 = require("../../context/context");
24var utils_1 = require("../../utils");
25var RowNodeBlockLoader = (function () {
26 function RowNodeBlockLoader(maxConcurrentRequests) {
27 this.activeBlockLoadsCount = 0;
28 this.blocks = [];
29 this.active = true;
30 this.maxConcurrentRequests = maxConcurrentRequests;
31 }
32 RowNodeBlockLoader.prototype.setBeans = function (loggerFactory) {
33 this.logger = loggerFactory.create('RowNodeBlockLoader');
34 };
35 RowNodeBlockLoader.prototype.addBlock = function (block) {
36 this.blocks.push(block);
37 };
38 RowNodeBlockLoader.prototype.removeBlock = function (block) {
39 utils_1._.removeFromArray(this.blocks, block);
40 };
41 RowNodeBlockLoader.prototype.destroy = function () {
42 this.active = false;
43 };
44 RowNodeBlockLoader.prototype.loadComplete = function () {
45 this.activeBlockLoadsCount--;
46 };
47 RowNodeBlockLoader.prototype.checkBlockToLoad = function () {
48 if (!this.active) {
49 return;
50 }
51 this.printCacheStatus();
52 if (this.activeBlockLoadsCount >= this.maxConcurrentRequests) {
53 this.logger.log("checkBlockToLoad: max loads exceeded");
54 return;
55 }
56 var blockToLoad = null;
57 this.blocks.forEach(function (block) {
58 if (block.getState() === rowNodeBlock_1.RowNodeBlock.STATE_DIRTY) {
59 blockToLoad = block;
60 }
61 });
62 if (blockToLoad) {
63 blockToLoad.load();
64 this.activeBlockLoadsCount++;
65 this.logger.log("checkBlockToLoad: loading page " + blockToLoad.getBlockNumber());
66 this.printCacheStatus();
67 }
68 else {
69 this.logger.log("checkBlockToLoad: no pages to load");
70 }
71 };
72 RowNodeBlockLoader.prototype.getBlockState = function () {
73 var result = {};
74 this.blocks.forEach(function (block) {
75 var nodeIdPrefix = block.getNodeIdPrefix();
76 var stateItem = {
77 blockNumber: block.getBlockNumber(),
78 startRow: block.getStartRow(),
79 endRow: block.getEndRow(),
80 pageStatus: block.getState()
81 };
82 if (utils_1._.exists(nodeIdPrefix)) {
83 result[nodeIdPrefix + block.getBlockNumber()] = stateItem;
84 }
85 else {
86 result[block.getBlockNumber()] = stateItem;
87 }
88 });
89 return result;
90 };
91 RowNodeBlockLoader.prototype.printCacheStatus = function () {
92 if (this.logger.isLogging()) {
93 this.logger.log("printCacheStatus: activePageLoadsCount = " + this.activeBlockLoadsCount + ","
94 + (" blocks = " + JSON.stringify(this.getBlockState())));
95 }
96 };
97 __decorate([
98 __param(0, context_1.Qualifier('loggerFactory')),
99 __metadata("design:type", Function),
100 __metadata("design:paramtypes", [logger_1.LoggerFactory]),
101 __metadata("design:returntype", void 0)
102 ], RowNodeBlockLoader.prototype, "setBeans", null);
103 return RowNodeBlockLoader;
104}());
105exports.RowNodeBlockLoader = RowNodeBlockLoader;