UNPKG

refraction

Version:

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

30 lines (22 loc) 482 B
export default class History { items = []; limit = 200; constructor(limit) { this.setLimit(limit); } setLimit(limit) { this.limit = Number(limit) > 0 ? Number(limit) : this.limit; } add(payload) { this.items.push(payload); if (this.items.length > this.limit) { this.items = this.items.slice(this.items.length - this.limit); } } get() { return this.items; } clear() { this.items = []; } }