UNPKG

2.87 kBJavaScriptView Raw
1"use strict";
2
3require("core-js/modules/es.array.for-each");
4
5require("core-js/modules/es.array.index-of");
6
7require("core-js/modules/es.array.splice");
8
9require("core-js/modules/es.object.assign");
10
11require("core-js/modules/es.object.define-property");
12
13require("core-js/modules/es.object.keys");
14
15require("core-js/modules/web.dom-collections.for-each");
16
17require("core-js/modules/web.timers");
18
19Object.defineProperty(exports, "__esModule", {
20 value: true
21});
22exports["default"] = void 0;
23
24function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
25
26function _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); } }
27
28function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
29
30var callArg = function callArg(fn) {
31 return fn();
32};
33
34var callAll = function callAll(fns) {
35 return fns.forEach(callArg);
36};
37
38var KnobStore =
39/*#__PURE__*/
40function () {
41 function KnobStore() {
42 _classCallCheck(this, KnobStore);
43
44 this.store = {};
45 this.callbacks = [];
46 this.timer = void 0;
47 }
48
49 _createClass(KnobStore, [{
50 key: "has",
51 value: function has(key) {
52 return this.store[key] !== undefined;
53 }
54 }, {
55 key: "set",
56 value: function set(key, value) {
57 this.store[key] = Object.assign({}, value, {
58 used: true,
59 groupId: value.groupId
60 }); // debounce the execution of the callbacks for 50 milliseconds
61
62 if (this.timer) {
63 clearTimeout(this.timer);
64 }
65
66 this.timer = setTimeout(callAll, 50, this.callbacks);
67 }
68 }, {
69 key: "get",
70 value: function get(key) {
71 var knob = this.store[key];
72
73 if (knob) {
74 knob.used = true;
75 }
76
77 return knob;
78 }
79 }, {
80 key: "getAll",
81 value: function getAll() {
82 return this.store;
83 }
84 }, {
85 key: "reset",
86 value: function reset() {
87 this.store = {};
88 }
89 }, {
90 key: "markAllUnused",
91 value: function markAllUnused() {
92 var _this = this;
93
94 Object.keys(this.store).forEach(function (knobName) {
95 _this.store[knobName].used = false;
96 });
97 }
98 }, {
99 key: "subscribe",
100 value: function subscribe(cb) {
101 this.callbacks.push(cb);
102 }
103 }, {
104 key: "unsubscribe",
105 value: function unsubscribe(cb) {
106 var index = this.callbacks.indexOf(cb);
107 this.callbacks.splice(index, 1);
108 }
109 }]);
110
111 return KnobStore;
112}();
113
114exports["default"] = KnobStore;
\No newline at end of file