@lcap/nasl
Version:
NetEase Application Specific Language
73 lines • 2.54 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DiagnosticManager = void 0;
const utils_1 = require("../utils");
class DiagnosticManager {
constructor() {
this.versions = Object.create(null);
this.records = [];
// 先使用 map 存放,降低被 vue 劫持的数组的内存消耗
this.records_map = new Map();
}
initVersionByFilePath(filePath) {
if (this.versions[filePath] === undefined) {
this.versions[filePath] = 0;
}
return this.versions[filePath];
}
incrementVersionByFilePath(filePath) {
this.initVersionByFilePath(filePath);
return ++this.versions[filePath];
}
getVersionByFilePath(filePath) {
// 单纯 get 不需要写入
return this.versions[filePath] ?? 0;
}
deleteVersionByFilePath(filePath) {
if (!filePath) {
return true;
}
delete this.versions[filePath];
}
push(record) {
const index = this.records.findIndex((item) => item.id === record.id);
if (index === -1) {
this.records.unshift(record);
}
else {
this.records.splice(index, 1, record);
}
}
getRecord(id) {
const index = this.records.findIndex((item) => item.id === id);
return this.records[index];
}
deleteOwn(id) {
let res = false;
const index = this.records.findIndex((item) => item.id === id);
if (index !== -1) {
const path = this.records[index].filePath;
if (path) {
res = true;
}
}
~index && this.records.splice(index, 1);
return res;
}
clear() {
this.records.splice(0, this.records.length);
this.versions = Object.create(null);
}
pushAll(records) {
return (0, utils_1.timeSlicingWithList)(records, (record) => this.push(record));
}
async setInitialDiagData(records) {
// 数组的地址不能变,否则 vue 监控不到。
// 请会 vue 的大佬改一改 packages/ide-essential/src/views/s-designer-foot.vue 里面的 problemsLen,让它数据都准备好后再展示数字
await (0, utils_1.timeSlicingWithList)(records, (record) => this.records_map.set(record.id, record));
this.records_map.forEach(val => this.records.push(val));
this.records_map.clear();
}
}
exports.DiagnosticManager = DiagnosticManager;
//# sourceMappingURL=diagnostic.js.map