epos-unit 1.0.2 → 1.0.4
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 +10 -9
- package/dist/epos-unit.js +16 -15
- package/package.json +1 -1
package/dist/epos-unit.d.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import { type Cls } from '@eposlabs/utils';
|
|
1
|
+
import { type Log, type Cls } from '@eposlabs/utils';
|
|
2
2
|
import { epos } from 'epos';
|
|
3
3
|
export declare const _root_: unique symbol;
|
|
4
|
+
export declare const _parent_: unique symbol;
|
|
4
5
|
export declare const _disposers_: unique symbol;
|
|
5
|
-
export declare
|
|
6
|
-
export declare class Unit {
|
|
6
|
+
export declare class Unit<TRoot = unknown> {
|
|
7
7
|
'@': string;
|
|
8
|
+
log: Log;
|
|
8
9
|
private [_root_];
|
|
10
|
+
private [_parent_];
|
|
9
11
|
private [_disposers_];
|
|
10
|
-
private [_tempParent_];
|
|
11
12
|
[key: PropertyKey]: unknown;
|
|
12
|
-
constructor(parent
|
|
13
|
-
[epos.
|
|
14
|
-
[epos.
|
|
15
|
-
static get [epos.
|
|
13
|
+
constructor(parent: Unit<TRoot> | null);
|
|
14
|
+
[epos.state.symbols.model.init](): void;
|
|
15
|
+
[epos.state.symbols.model.cleanup](): void;
|
|
16
|
+
static get [epos.state.symbols.model.versioner](): unknown;
|
|
16
17
|
static defineVersioner(versioner: Record<number, (this: any, unit: any) => void>): Record<number, (this: any, unit: any) => void>;
|
|
17
|
-
get $():
|
|
18
|
+
get $(): TRoot;
|
|
18
19
|
up<T extends Unit>(Ancestor: Cls<T>): T | null;
|
|
19
20
|
autorun(...args: Parameters<typeof epos.libs.mobx.autorun>): import("mobx").IReactionDisposer;
|
|
20
21
|
reaction(...args: Parameters<typeof epos.libs.mobx.reaction>): import("mobx").IReactionDisposer;
|
package/dist/epos-unit.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { createLog } from '@eposlabs/utils';
|
|
2
2
|
import { epos } from 'epos';
|
|
3
3
|
export const _root_ = Symbol('root');
|
|
4
|
+
export const _parent_ = Symbol('parent');
|
|
4
5
|
export const _disposers_ = Symbol('disposers');
|
|
5
|
-
export const _tempParent_ = Symbol('parent');
|
|
6
6
|
export class Unit {
|
|
7
|
-
constructor(parent
|
|
8
|
-
this
|
|
7
|
+
constructor(parent) {
|
|
8
|
+
Reflect.defineProperty(this, _parent_, { get: () => parent });
|
|
9
9
|
}
|
|
10
10
|
// ---------------------------------------------------------------------------
|
|
11
11
|
// INIT
|
|
12
12
|
// ---------------------------------------------------------------------------
|
|
13
|
-
[epos.
|
|
13
|
+
[epos.state.symbols.model.init]() {
|
|
14
14
|
const Unit = this.constructor;
|
|
15
15
|
const prototypeKeys = Object.getOwnPropertyNames(Unit.prototype);
|
|
16
16
|
// Set disposers container
|
|
17
|
-
|
|
17
|
+
const disposers = new Set();
|
|
18
|
+
Reflect.defineProperty(this, _disposers_, { get: () => disposers });
|
|
18
19
|
// Bind all methods
|
|
19
20
|
for (const key of prototypeKeys) {
|
|
20
21
|
if (typeof this[key] !== 'function')
|
|
@@ -29,7 +30,7 @@ export class Unit {
|
|
|
29
30
|
continue;
|
|
30
31
|
if (!isUiKey(key))
|
|
31
32
|
continue;
|
|
32
|
-
const componentName =
|
|
33
|
+
const componentName = [this['@'], key.replace('ui', '')].filter(Boolean).join('-');
|
|
33
34
|
this[key] = epos.component(componentName, this[key]);
|
|
34
35
|
}
|
|
35
36
|
// Define log method
|
|
@@ -42,10 +43,10 @@ export class Unit {
|
|
|
42
43
|
// ---------------------------------------------------------------------------
|
|
43
44
|
// CLEANUP
|
|
44
45
|
// ---------------------------------------------------------------------------
|
|
45
|
-
[epos.
|
|
46
|
+
[epos.state.symbols.model.cleanup]() {
|
|
46
47
|
// Call disposers
|
|
47
48
|
this[_disposers_].forEach(disposer => disposer());
|
|
48
|
-
this[_disposers_]
|
|
49
|
+
this[_disposers_].clear();
|
|
49
50
|
// Call cleanup method
|
|
50
51
|
if (typeof this.cleanup === 'function')
|
|
51
52
|
this.cleanup();
|
|
@@ -53,7 +54,7 @@ export class Unit {
|
|
|
53
54
|
// ---------------------------------------------------------------------------
|
|
54
55
|
// VERSIONER
|
|
55
56
|
// ---------------------------------------------------------------------------
|
|
56
|
-
static get [epos.
|
|
57
|
+
static get [epos.state.symbols.model.versioner]() {
|
|
57
58
|
if (!('versioner' in this))
|
|
58
59
|
return null;
|
|
59
60
|
return this.versioner;
|
|
@@ -79,22 +80,22 @@ export class Unit {
|
|
|
79
80
|
}
|
|
80
81
|
autorun(...args) {
|
|
81
82
|
const disposer = epos.libs.mobx.autorun(...args);
|
|
82
|
-
this[_disposers_].
|
|
83
|
+
this[_disposers_].add(disposer);
|
|
83
84
|
return disposer;
|
|
84
85
|
}
|
|
85
86
|
reaction(...args) {
|
|
86
87
|
const disposer = epos.libs.mobx.reaction(...args);
|
|
87
|
-
this[_disposers_].
|
|
88
|
+
this[_disposers_].add(disposer);
|
|
88
89
|
return disposer;
|
|
89
90
|
}
|
|
90
91
|
setTimeout(...args) {
|
|
91
92
|
const id = self.setTimeout(...args);
|
|
92
|
-
this[_disposers_].
|
|
93
|
+
this[_disposers_].add(() => self.clearTimeout(id));
|
|
93
94
|
return id;
|
|
94
95
|
}
|
|
95
96
|
setInterval(...args) {
|
|
96
97
|
const id = self.setInterval(...args);
|
|
97
|
-
this[_disposers_].
|
|
98
|
+
this[_disposers_].add(() => self.clearInterval(id));
|
|
98
99
|
return id;
|
|
99
100
|
}
|
|
100
101
|
}
|
|
@@ -102,10 +103,10 @@ export class Unit {
|
|
|
102
103
|
// HELPERS
|
|
103
104
|
// ---------------------------------------------------------------------------
|
|
104
105
|
function isUiKey(key) {
|
|
105
|
-
return key
|
|
106
|
+
return key.startsWith('ui');
|
|
106
107
|
}
|
|
107
108
|
function getParent(child) {
|
|
108
|
-
return child[
|
|
109
|
+
return child[_parent_] ?? child[epos.state.symbols.model.parent];
|
|
109
110
|
}
|
|
110
111
|
function findRoot(unit) {
|
|
111
112
|
let root = unit;
|