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 = function () {
|
39 | function KnobStore() {
|
40 | _classCallCheck(this, KnobStore);
|
41 |
|
42 | this.store = {};
|
43 | this.callbacks = [];
|
44 | this.timer = void 0;
|
45 | }
|
46 |
|
47 | _createClass(KnobStore, [{
|
48 | key: "has",
|
49 | value: function has(key) {
|
50 | return this.store[key] !== undefined;
|
51 | }
|
52 | }, {
|
53 | key: "set",
|
54 | value: function set(key, value) {
|
55 | this.store[key] = Object.assign(Object.assign({}, value), {}, {
|
56 | used: true,
|
57 | groupId: value.groupId
|
58 | });
|
59 |
|
60 | if (this.timer) {
|
61 | clearTimeout(this.timer);
|
62 | }
|
63 |
|
64 | this.timer = setTimeout(callAll, 50, this.callbacks);
|
65 | }
|
66 | }, {
|
67 | key: "update",
|
68 | value: function update(key, options) {
|
69 | this.store[key] = Object.assign(Object.assign({}, this.store[key]), options);
|
70 | }
|
71 | }, {
|
72 | key: "get",
|
73 | value: function get(key) {
|
74 | var knob = this.store[key];
|
75 |
|
76 | if (knob) {
|
77 | knob.used = true;
|
78 | }
|
79 |
|
80 | return knob;
|
81 | }
|
82 | }, {
|
83 | key: "getAll",
|
84 | value: function getAll() {
|
85 | return this.store;
|
86 | }
|
87 | }, {
|
88 | key: "reset",
|
89 | value: function reset() {
|
90 | this.store = {};
|
91 | }
|
92 | }, {
|
93 | key: "markAllUnused",
|
94 | value: function markAllUnused() {
|
95 | var _this = this;
|
96 |
|
97 | Object.keys(this.store).forEach(function (knobName) {
|
98 | _this.store[knobName].used = false;
|
99 | });
|
100 | }
|
101 | }, {
|
102 | key: "subscribe",
|
103 | value: function subscribe(cb) {
|
104 | this.callbacks.push(cb);
|
105 | }
|
106 | }, {
|
107 | key: "unsubscribe",
|
108 | value: function unsubscribe(cb) {
|
109 | var index = this.callbacks.indexOf(cb);
|
110 | this.callbacks.splice(index, 1);
|
111 | }
|
112 | }]);
|
113 |
|
114 | return KnobStore;
|
115 | }();
|
116 |
|
117 | exports["default"] = KnobStore; |
\ | No newline at end of file |