UNPKG

@atlaskit/editor-plugin-interactivity

Version:

Interactivity plugin for @atlaskit/editor-core

35 lines 1.18 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; /** An array that forgets its oldest item once it holds more than `limit`. */ export var BoundedList = /*#__PURE__*/function () { function BoundedList(limit) { _classCallCheck(this, BoundedList); _defineProperty(this, "items", []); this.limit = limit; } return _createClass(BoundedList, [{ key: "push", value: function push() { var _this$items; (_this$items = this.items).push.apply(_this$items, arguments); // Negative when there is still room, and `splice` then removes nothing. this.items.splice(0, this.items.length - this.limit); } }, { key: Symbol.iterator, value: function value() { return this.items[Symbol.iterator](); } }, { key: "findLast", value: function findLast(matches) { for (var index = this.items.length - 1; index >= 0; index -= 1) { if (matches(this.items[index])) { return this.items[index]; } } return undefined; } }]); }();