1 | "use strict";
|
2 |
|
3 | require("core-js/modules/es.array.for-each");
|
4 |
|
5 | require("core-js/modules/es.array.index-of");
|
6 |
|
7 | require("core-js/modules/es.array.splice");
|
8 |
|
9 | require("core-js/modules/es.object.assign");
|
10 |
|
11 | require("core-js/modules/es.object.define-property");
|
12 |
|
13 | require("core-js/modules/es.object.keys");
|
14 |
|
15 | require("core-js/modules/web.dom-collections.for-each");
|
16 |
|
17 | require("core-js/modules/web.timers");
|
18 |
|
19 | Object.defineProperty(exports, "__esModule", {
|
20 | value: true
|
21 | });
|
22 | exports["default"] = void 0;
|
23 |
|
24 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
25 |
|
26 | 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); } }
|
27 |
|
28 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
29 |
|
30 | var callArg = function callArg(fn) {
|
31 | return fn();
|
32 | };
|
33 |
|
34 | var callAll = function callAll(fns) {
|
35 | return fns.forEach(callArg);
|
36 | };
|
37 |
|
38 | var KnobStore =
|
39 |
|
40 | function () {
|
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 | });
|
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 |
|
114 | exports["default"] = KnobStore; |
\ | No newline at end of file |