UNPKG

refraction

Version:

A guard that represent central point of control in your application.

49 lines (40 loc) 1.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var History = function () { function History(limit) { _classCallCheck(this, History); this.items = []; this.limit = 200; this.setLimit(limit); } _createClass(History, [{ key: "setLimit", value: function setLimit(limit) { this.limit = Number(limit) > 0 ? Number(limit) : this.limit; } }, { key: "add", value: function add(payload) { this.items.push(payload); if (this.items.length > this.limit) { this.items = this.items.slice(this.items.length - this.limit); } } }, { key: "get", value: function get() { return this.items; } }, { key: "clear", value: function clear() { this.items = []; } }]); return History; }(); exports["default"] = History;