smoothly 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var _Listenable_listeners;
|
|
7
|
+
export class Listenable {
|
|
8
|
+
constructor() {
|
|
9
|
+
_Listenable_listeners.set(this, {});
|
|
10
|
+
}
|
|
11
|
+
listen(event, listener) {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
(_b = (_a = __classPrivateFieldGet(this, _Listenable_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.push(listener)) !== null && _b !== void 0 ? _b : (__classPrivateFieldGet(this, _Listenable_listeners, "f")[event] = [listener]);
|
|
14
|
+
listener(this[event]);
|
|
15
|
+
}
|
|
16
|
+
static load(backend) {
|
|
17
|
+
const result = new Listenable();
|
|
18
|
+
for (const property in backend) {
|
|
19
|
+
if (Object.prototype.hasOwnProperty.call(backend, property)) {
|
|
20
|
+
Object.defineProperty(result, property, {
|
|
21
|
+
get() {
|
|
22
|
+
return backend[property];
|
|
23
|
+
},
|
|
24
|
+
set(v) {
|
|
25
|
+
var _a;
|
|
26
|
+
backend[property] = v;
|
|
27
|
+
(_a = __classPrivateFieldGet(result, _Listenable_listeners, "f")[property]) === null || _a === void 0 ? void 0 : _a.forEach(l => l(v));
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
_Listenable_listeners = new WeakMap();
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
|
+
};
|
|
12
|
+
var _State_id, _State_all;
|
|
13
|
+
import { Listenable } from "./Listenable";
|
|
14
|
+
export class State {
|
|
15
|
+
constructor() {
|
|
16
|
+
_State_id.set(this, void 0);
|
|
17
|
+
_State_all.set(this, void 0);
|
|
18
|
+
}
|
|
19
|
+
get id() {
|
|
20
|
+
return __classPrivateFieldGet(this, _State_id, "f");
|
|
21
|
+
}
|
|
22
|
+
set id(value) {
|
|
23
|
+
__classPrivateFieldSet(this, _State_id, value, "f");
|
|
24
|
+
this.all = undefined;
|
|
25
|
+
}
|
|
26
|
+
get all() {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
return (_a = __classPrivateFieldGet(this, _State_all, "f")) !== null && _a !== void 0 ? _a : (__classPrivateFieldSet(this, _State_all, load((_b = this.id) !== null && _b !== void 0 ? _b : 0), "f"));
|
|
29
|
+
}
|
|
30
|
+
set all(value) {
|
|
31
|
+
__classPrivateFieldSet(this, _State_all, value, "f");
|
|
32
|
+
this.current = value === null || value === void 0 ? void 0 : value[0];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
_State_id = new WeakMap(), _State_all = new WeakMap();
|
|
36
|
+
const state = Listenable.load(new State());
|
|
37
|
+
state.listen("current", current => console.log(current));
|
|
38
|
+
function load(id) {
|
|
39
|
+
return [id, id + 1];
|
|
40
|
+
}
|