UNPKG

@itwin/presentation-frontend

Version:

Frontend of iModel.js Presentation library

88 lines 2.86 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module Core */ Object.defineProperty(exports, "__esModule", { value: true }); exports.RulesetManagerImpl = void 0; const core_bentley_1 = require("@itwin/core-bentley"); const presentation_common_1 = require("@itwin/presentation-common"); /** @internal */ class RulesetManagerImpl { _clientRulesets = new Map(); onRulesetModified = new core_bentley_1.BeEvent(); static create() { return new RulesetManagerImpl(); } /** * Get a ruleset with the specified id. */ async get(id) { const m = this._clientRulesets.get(id); if (!m) { return undefined; } return m[0]; } /** * Register the supplied ruleset */ async add(ruleset) { const registered = new presentation_common_1.RegisteredRuleset(ruleset, core_bentley_1.Guid.createValue(), async (r) => this.remove(r)); if (!this._clientRulesets.has(ruleset.id)) { this._clientRulesets.set(ruleset.id, []); } this._clientRulesets.get(ruleset.id).push(registered); return registered; } /** * Modifies the given pre-registered ruleset */ async modify(ruleset, newRules) { await this.remove(ruleset); const modified = await this.add({ ...newRules, id: ruleset.id }); this.onRulesetModified.raiseEvent(modified, ruleset.toJSON()); return modified; } /** * Unregister the supplied ruleset */ async remove(ruleset) { let rulesetId, uniqueIdentifier; if (Array.isArray(ruleset)) { rulesetId = ruleset[0]; uniqueIdentifier = ruleset[1]; } else { rulesetId = ruleset.id; uniqueIdentifier = ruleset.uniqueIdentifier; } const m = this._clientRulesets.get(rulesetId); if (!m) { return false; } let didRemove = false; for (let i = 0; i < m.length; ++i) { if (m[i].uniqueIdentifier === uniqueIdentifier) { m.splice(i, 1); didRemove = true; break; } } return didRemove; } /** * Remove all rulesets registered in this session. */ async clear() { if (0 === this._clientRulesets.size) { return; } this._clientRulesets.clear(); } } exports.RulesetManagerImpl = RulesetManagerImpl; //# sourceMappingURL=RulesetManager.js.map