epos-unit 1.1.5 → 1.1.7
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.
- package/dist/epos-unit.d.ts +1 -1
- package/dist/epos-unit.js +7 -5
- package/package.json +3 -3
- package/src/epos-unit.ts +11 -8
package/dist/epos-unit.d.ts
CHANGED
|
@@ -8,10 +8,10 @@ type Descriptors = Record<string | symbol, PropertyDescriptor>;
|
|
|
8
8
|
declare class Unit<TRoot = unknown> {
|
|
9
9
|
'@': string;
|
|
10
10
|
log: Log;
|
|
11
|
+
[':version']?: number;
|
|
11
12
|
private [_root_];
|
|
12
13
|
private [_parent_];
|
|
13
14
|
private [_disposers_];
|
|
14
|
-
[key: PropertyKey]: unknown;
|
|
15
15
|
constructor(parent: Unit<TRoot> | null);
|
|
16
16
|
[epos.state.symbols.modelInit](): void;
|
|
17
17
|
[epos.state.symbols.modelCleanup](): void;
|
package/dist/epos-unit.js
CHANGED
|
@@ -12,6 +12,7 @@ var Unit = class {
|
|
|
12
12
|
// INIT
|
|
13
13
|
// ---------------------------------------------------------------------------
|
|
14
14
|
[epos.state.symbols.modelInit]() {
|
|
15
|
+
const _this = this;
|
|
15
16
|
const Unit2 = this.constructor;
|
|
16
17
|
const descriptors = Object.getOwnPropertyDescriptors(Unit2.prototype);
|
|
17
18
|
const keys = Reflect.ownKeys(descriptors);
|
|
@@ -22,28 +23,29 @@ var Unit = class {
|
|
|
22
23
|
const descriptor = descriptors[key];
|
|
23
24
|
if (descriptor.get || descriptor.set) continue;
|
|
24
25
|
if (typeof descriptor.value !== "function") continue;
|
|
25
|
-
|
|
26
|
+
_this[key] = descriptor.value.bind(this);
|
|
26
27
|
}
|
|
27
28
|
for (const key of keys) {
|
|
28
29
|
if (typeof key === "symbol") continue;
|
|
29
30
|
if (!key.startsWith("ui")) continue;
|
|
30
31
|
const descriptor = descriptors[key];
|
|
31
32
|
if (descriptor.get || descriptor.set) continue;
|
|
32
|
-
if (typeof
|
|
33
|
+
if (typeof _this[key] !== "function") continue;
|
|
33
34
|
const componentName = [this["@"], key.replace("ui", "")].filter(Boolean).join("-");
|
|
34
|
-
|
|
35
|
+
_this[key] = epos.component(componentName, _this[key]);
|
|
35
36
|
}
|
|
36
37
|
const log = createLog(this["@"]);
|
|
37
38
|
Reflect.defineProperty(this, "log", { get: () => log });
|
|
38
|
-
if (typeof
|
|
39
|
+
if (typeof _this.init === "function") _this.init();
|
|
39
40
|
}
|
|
40
41
|
// ---------------------------------------------------------------------------
|
|
41
42
|
// CLEANUP
|
|
42
43
|
// ---------------------------------------------------------------------------
|
|
43
44
|
[epos.state.symbols.modelCleanup]() {
|
|
45
|
+
const _this = this;
|
|
44
46
|
this[_disposers_].forEach((disposer) => disposer());
|
|
45
47
|
this[_disposers_].clear();
|
|
46
|
-
if (typeof
|
|
48
|
+
if (typeof _this.cleanup === "function") _this.cleanup();
|
|
47
49
|
}
|
|
48
50
|
// ---------------------------------------------------------------------------
|
|
49
51
|
// VERSIONER
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "epos-unit",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "imkost",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"dist"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@eposlabs/utils": "^1.2.
|
|
28
|
-
"epos": "^1.8.
|
|
27
|
+
"@eposlabs/utils": "^1.2.2",
|
|
28
|
+
"epos": "^1.8.5"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/epos-unit.ts
CHANGED
|
@@ -9,11 +9,11 @@ export type Descriptors = Record<string | symbol, PropertyDescriptor>
|
|
|
9
9
|
|
|
10
10
|
export class Unit<TRoot = unknown> {
|
|
11
11
|
declare '@': string
|
|
12
|
-
declare log: Log
|
|
12
|
+
declare log: Log;
|
|
13
|
+
declare [':version']?: number
|
|
13
14
|
declare private [_root_]: TRoot
|
|
14
15
|
declare private [_parent_]: Unit<TRoot> | null // Parent reference for not-yet-attached units
|
|
15
|
-
declare private [_disposers_]: Set<() => void
|
|
16
|
-
[key: PropertyKey]: unknown
|
|
16
|
+
declare private [_disposers_]: Set<() => void>
|
|
17
17
|
|
|
18
18
|
constructor(parent: Unit<TRoot> | null) {
|
|
19
19
|
// Define parent for not-yet-attached units
|
|
@@ -25,6 +25,7 @@ export class Unit<TRoot = unknown> {
|
|
|
25
25
|
// ---------------------------------------------------------------------------
|
|
26
26
|
|
|
27
27
|
[epos.state.symbols.modelInit]() {
|
|
28
|
+
const _this = this as any
|
|
28
29
|
const Unit = this.constructor
|
|
29
30
|
const descriptors: Descriptors = Object.getOwnPropertyDescriptors(Unit.prototype)
|
|
30
31
|
const keys = Reflect.ownKeys(descriptors)
|
|
@@ -39,7 +40,7 @@ export class Unit<TRoot = unknown> {
|
|
|
39
40
|
const descriptor = descriptors[key]
|
|
40
41
|
if (descriptor.get || descriptor.set) continue
|
|
41
42
|
if (typeof descriptor.value !== 'function') continue
|
|
42
|
-
|
|
43
|
+
_this[key] = descriptor.value.bind(this)
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
// Wrap UI methods to components
|
|
@@ -48,9 +49,9 @@ export class Unit<TRoot = unknown> {
|
|
|
48
49
|
if (!key.startsWith('ui')) continue
|
|
49
50
|
const descriptor = descriptors[key]
|
|
50
51
|
if (descriptor.get || descriptor.set) continue
|
|
51
|
-
if (typeof
|
|
52
|
+
if (typeof _this[key] !== 'function') continue
|
|
52
53
|
const componentName = [this['@'], key.replace('ui', '')].filter(Boolean).join('-')
|
|
53
|
-
|
|
54
|
+
_this[key] = epos.component(componentName, _this[key] as FC)
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
// Define log method
|
|
@@ -58,7 +59,7 @@ export class Unit<TRoot = unknown> {
|
|
|
58
59
|
Reflect.defineProperty(this, 'log', { get: () => log })
|
|
59
60
|
|
|
60
61
|
// Call init method
|
|
61
|
-
if (typeof
|
|
62
|
+
if (typeof _this.init === 'function') _this.init()
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
// ---------------------------------------------------------------------------
|
|
@@ -66,12 +67,14 @@ export class Unit<TRoot = unknown> {
|
|
|
66
67
|
// ---------------------------------------------------------------------------
|
|
67
68
|
|
|
68
69
|
[epos.state.symbols.modelCleanup]() {
|
|
70
|
+
const _this = this as any
|
|
71
|
+
|
|
69
72
|
// Call disposers
|
|
70
73
|
this[_disposers_].forEach(disposer => disposer())
|
|
71
74
|
this[_disposers_].clear()
|
|
72
75
|
|
|
73
76
|
// Call cleanup method
|
|
74
|
-
if (typeof
|
|
77
|
+
if (typeof _this.cleanup === 'function') _this.cleanup()
|
|
75
78
|
}
|
|
76
79
|
|
|
77
80
|
// ---------------------------------------------------------------------------
|