UNPKG

@barchart/common-js

Version:
117 lines (111 loc) 3.81 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var DisposableStack_exports = {}; __export(DisposableStack_exports, { default: () => DisposableStack }); module.exports = __toCommonJS(DisposableStack_exports); var assert = __toESM(require("./../../lang/assert.js")); var is = __toESM(require("./../../lang/is.js")); var import_Stack = __toESM(require("./../Stack.js")); var import_Disposable = __toESM(require("./../../lang/Disposable.js")); class DisposableStack extends import_Disposable.default { #stack; constructor() { super(); this.#stack = new import_Stack.default(); } /** * Adds a new {@link Disposable} instance to the stack. * * @public * @param {Disposable} disposable - The item to add. */ push(disposable) { assert.argumentIsRequired(disposable, "disposable", import_Disposable.default, "Disposable"); if (this.disposed) { throw new Error("Unable to push item onto DisposableStack because it has been disposed."); } this.#stack.push(disposable); } /** * @protected * @override */ _onDispose() { while (!this.#stack.empty()) { this.#stack.pop().dispose(); } } /** * @public * @static * @param {*} bindings * @returns {DisposableStack} */ static fromArray(bindings) { assert.argumentIsArray(bindings, "bindings", import_Disposable.default, "Disposable"); const returnRef = new DisposableStack(); for (let i = 0; i < bindings.length; i++) { returnRef.push(bindings[i]); } return returnRef; } /** * @public * @static * @async * @param {*} stack * @param {*} promise * @returns {Promise} */ static async pushPromise(stack, promise) { assert.argumentIsRequired(stack, "stack", DisposableStack, "DisposableStack"); assert.argumentIsRequired(promise, "promise"); const b = await promise; let bindings; if (is.array(b)) { bindings = b; } else { bindings = [b]; } bindings.forEach((binding) => stack.push(binding)); } } { const cjsExports = module.exports; const cjsDefaultExport = cjsExports && cjsExports.__esModule ? cjsExports.default : cjsExports; if (cjsDefaultExport && (typeof cjsDefaultExport === 'function' || typeof cjsDefaultExport === 'object')) { Object.keys(cjsExports).forEach((key) => { if (key !== 'default' && key !== '__esModule') { cjsDefaultExport[key] = cjsExports[key]; } }); } module.exports = cjsDefaultExport; }