UNPKG

@atlaskit/editor-plugin-interactivity

Version:

Interactivity plugin for @atlaskit/editor-core

35 lines 1.05 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; /** A `Map` that forgets its oldest entry once it holds more than `limit`. */ export var BoundedMap = /*#__PURE__*/function () { function BoundedMap(limit) { _classCallCheck(this, BoundedMap); _defineProperty(this, "entries", new Map()); this.limit = limit; } return _createClass(BoundedMap, [{ key: "get", value: function get(key) { return this.entries.get(key); } }, { key: "forEach", value: function forEach(visit) { this.entries.forEach(visit); } }, { key: "set", value: function set(key, value) { this.entries.delete(key); this.entries.set(key, value); if (this.entries.size <= this.limit) { return; } var oldest = this.entries.keys().next(); if (!oldest.done) { this.entries.delete(oldest.value); } } }]); }();