epos-unit 1.0.4 → 1.0.5
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 +2 -2
- package/dist/epos-unit.js +20 -13
- package/package.json +1 -1
package/dist/epos-unit.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Cls, type Log } from '@eposlabs/utils';
|
|
2
2
|
import { epos } from 'epos';
|
|
3
3
|
export declare const _root_: unique symbol;
|
|
4
4
|
export declare const _parent_: unique symbol;
|
|
5
5
|
export declare const _disposers_: unique symbol;
|
|
6
6
|
export declare class Unit<TRoot = unknown> {
|
|
7
7
|
'@': string;
|
|
8
|
-
log: Log;
|
|
8
|
+
'log': Log;
|
|
9
9
|
private [_root_];
|
|
10
10
|
private [_parent_];
|
|
11
11
|
private [_disposers_];
|
package/dist/epos-unit.js
CHANGED
|
@@ -5,6 +5,7 @@ export const _parent_ = Symbol('parent');
|
|
|
5
5
|
export const _disposers_ = Symbol('disposers');
|
|
6
6
|
export class Unit {
|
|
7
7
|
constructor(parent) {
|
|
8
|
+
// Define parent for not-yet-attached units
|
|
8
9
|
Reflect.defineProperty(this, _parent_, { get: () => parent });
|
|
9
10
|
}
|
|
10
11
|
// ---------------------------------------------------------------------------
|
|
@@ -12,26 +13,32 @@ export class Unit {
|
|
|
12
13
|
// ---------------------------------------------------------------------------
|
|
13
14
|
[epos.state.symbols.model.init]() {
|
|
14
15
|
const Unit = this.constructor;
|
|
15
|
-
const
|
|
16
|
+
const descriptors = Object.getOwnPropertyDescriptors(Unit.prototype);
|
|
16
17
|
// Set disposers container
|
|
17
18
|
const disposers = new Set();
|
|
18
19
|
Reflect.defineProperty(this, _disposers_, { get: () => disposers });
|
|
19
20
|
// Bind all methods
|
|
20
|
-
for (const key
|
|
21
|
-
|
|
22
|
-
continue;
|
|
21
|
+
for (const key in descriptors) {
|
|
22
|
+
const descriptor = descriptors[key];
|
|
23
23
|
if (key === 'constructor')
|
|
24
24
|
continue;
|
|
25
|
-
|
|
25
|
+
if (descriptor.get || descriptor.set)
|
|
26
|
+
continue;
|
|
27
|
+
if (typeof descriptor.value !== 'function')
|
|
28
|
+
continue;
|
|
29
|
+
this[key] = descriptor.value.bind(this);
|
|
26
30
|
}
|
|
27
31
|
// Wrap UI methods to components
|
|
28
|
-
for (const key
|
|
29
|
-
|
|
32
|
+
for (const key in descriptors) {
|
|
33
|
+
const descriptor = descriptors[key];
|
|
34
|
+
if (!key.startsWith('ui'))
|
|
35
|
+
continue;
|
|
36
|
+
if (descriptor.get || descriptor.set)
|
|
30
37
|
continue;
|
|
31
|
-
if (
|
|
38
|
+
if (typeof descriptor.value !== 'function')
|
|
32
39
|
continue;
|
|
33
40
|
const componentName = [this['@'], key.replace('ui', '')].filter(Boolean).join('-');
|
|
34
|
-
this[key] = epos.component(componentName,
|
|
41
|
+
this[key] = epos.component(componentName, descriptor.value);
|
|
35
42
|
}
|
|
36
43
|
// Define log method
|
|
37
44
|
const log = createLog(this['@']);
|
|
@@ -63,12 +70,15 @@ export class Unit {
|
|
|
63
70
|
return versioner;
|
|
64
71
|
}
|
|
65
72
|
// ---------------------------------------------------------------------------
|
|
66
|
-
//
|
|
73
|
+
// ROOT
|
|
67
74
|
// ---------------------------------------------------------------------------
|
|
68
75
|
get $() {
|
|
69
76
|
this[_root_] ??= findRoot(this);
|
|
70
77
|
return this[_root_];
|
|
71
78
|
}
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
// METHODS
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
72
82
|
up(Ancestor) {
|
|
73
83
|
let cursor = getParent(this);
|
|
74
84
|
while (cursor) {
|
|
@@ -102,9 +112,6 @@ export class Unit {
|
|
|
102
112
|
// ---------------------------------------------------------------------------
|
|
103
113
|
// HELPERS
|
|
104
114
|
// ---------------------------------------------------------------------------
|
|
105
|
-
function isUiKey(key) {
|
|
106
|
-
return key.startsWith('ui');
|
|
107
|
-
}
|
|
108
115
|
function getParent(child) {
|
|
109
116
|
return child[_parent_] ?? child[epos.state.symbols.model.parent];
|
|
110
117
|
}
|