UNPKG

@atlaskit/editor-plugin-interactivity

Version:

Interactivity plugin for @atlaskit/editor-core

42 lines (41 loc) 1.52 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.BoundedList = void 0; var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); /** An array that forgets its oldest item once it holds more than `limit`. */ var BoundedList = exports.BoundedList = /*#__PURE__*/function () { function BoundedList(limit) { (0, _classCallCheck2.default)(this, BoundedList); (0, _defineProperty2.default)(this, "items", []); this.limit = limit; } return (0, _createClass2.default)(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; } }]); }();