UNPKG

@atlaskit/editor-plugin-interactivity

Version:

Interactivity plugin for @atlaskit/editor-core

24 lines 731 B
import _defineProperty from "@babel/runtime/helpers/defineProperty"; /** An array that forgets its oldest item once it holds more than `limit`. */ export class BoundedList { constructor(limit) { _defineProperty(this, "items", []); this.limit = limit; } push(...items) { this.items.push(...items); // Negative when there is still room, and `splice` then removes nothing. this.items.splice(0, this.items.length - this.limit); } [Symbol.iterator]() { return this.items[Symbol.iterator](); } findLast(matches) { for (let index = this.items.length - 1; index >= 0; index -= 1) { if (matches(this.items[index])) { return this.items[index]; } } return undefined; } }