UNPKG

agora-edu-core

Version:

Core APIs for building an online classroom

74 lines (72 loc) 2.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BatchRecord = void 0; require("core-js/modules/esnext.map.delete-all.js"); require("core-js/modules/esnext.map.every.js"); require("core-js/modules/esnext.map.filter.js"); require("core-js/modules/esnext.map.find.js"); require("core-js/modules/esnext.map.find-key.js"); require("core-js/modules/esnext.map.includes.js"); require("core-js/modules/esnext.map.key-of.js"); require("core-js/modules/esnext.map.map-keys.js"); require("core-js/modules/esnext.map.map-values.js"); require("core-js/modules/esnext.map.merge.js"); require("core-js/modules/esnext.map.reduce.js"); require("core-js/modules/esnext.map.some.js"); require("core-js/modules/esnext.map.update.js"); var _BatchRecord; /** * 此类主要处理将多个数据包中的同一批变更合并到一起,合并完成后执行callback * */ /** @en * */ class BatchRecord { static getBatchRecord(batchId) { if (!this._batchRecords.has(batchId)) { this._batchRecords.set(batchId, new BatchRecord(batchId)); } const batchRecord = this._batchRecords.get(batchId); return batchRecord; } constructor(_batchId) { let _total = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; let _current = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; let _cb = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : dataChunk => {}; this._batchId = _batchId; this._total = _total; this._current = _current; this._cb = _cb; this._dataChunk = []; } addChunk(data) { this._dataChunk.push(data); return this; } setCallback(cb) { this._cb = cb; return this; } setTotal(total) { this._total = total; return this; } setCurrent(current) { this._current = current; return this; } execute() { if (this._total === this._current) { BatchRecord._batchRecords.delete(this._batchId); if (this._cb) { this._cb.apply(this, [this._dataChunk]); } } } } exports.BatchRecord = BatchRecord; _BatchRecord = BatchRecord; BatchRecord._batchRecords = new Map();