UNPKG

@atlaskit/editor-plugin-interactivity

Version:

Interactivity plugin for @atlaskit/editor-core

25 lines 650 B
import _defineProperty from "@babel/runtime/helpers/defineProperty"; /** A `Map` that forgets its oldest entry once it holds more than `limit`. */ export class BoundedMap { constructor(limit) { _defineProperty(this, "entries", new Map()); this.limit = limit; } get(key) { return this.entries.get(key); } forEach(visit) { this.entries.forEach(visit); } set(key, value) { this.entries.delete(key); this.entries.set(key, value); if (this.entries.size <= this.limit) { return; } const oldest = this.entries.keys().next(); if (!oldest.done) { this.entries.delete(oldest.value); } } }