UNPKG

@malagu/core

Version:
58 lines 2.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ContainerBasedProvider = void 0; const provider_protocol_1 = require("./provider-protocol"); const utils_1 = require("../utils"); const DEFAULT_GET_PRIORITY = value => { if (value) { if ('priority' in value) { return value.priority; } else if ('order' in value) { return value.order; } return 0; } }; class ContainerBasedProvider { constructor(componentId, container) { this.componentId = componentId; this.container = container; } get(recursive) { if (this.components === undefined) { const currentComponents = []; let filterRegistry; let currentContainer = this.container; // eslint-disable-next-line no-null/no-null while (currentContainer !== null) { if (currentContainer.isBound(this.componentId)) { try { currentComponents.push(...currentContainer.getAll(this.componentId)); } catch (error) { console.error(error); } } if (filterRegistry === undefined && currentContainer.isBound(provider_protocol_1.ComponentFilterRegistry)) { filterRegistry = currentContainer.get(provider_protocol_1.ComponentFilterRegistry); } // eslint-disable-next-line no-null/no-null currentContainer = recursive === true ? currentContainer.parent : null; } this.components = filterRegistry ? filterRegistry.applyFilters(currentComponents, this.componentId) : currentComponents; } return this.components; } sortSync(getPriority = DEFAULT_GET_PRIORITY, recursive) { this.components = utils_1.Prioritizeable.prioritizeAllSync(this.get(recursive), getPriority).map(c => c.value); return this.components; } async sort(getPriority = DEFAULT_GET_PRIORITY, recursive) { const result = await utils_1.Prioritizeable.prioritizeAll(this.get(recursive), getPriority); this.components = result.map(c => c.value); return this.components; } } exports.ContainerBasedProvider = ContainerBasedProvider; //# sourceMappingURL=provider.js.map