epos-unit 1.23.0 → 1.27.0
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 +31 -26
- package/dist/epos-unit.js +160 -166
- package/dist/epos-unit.js.map +1 -1
- package/package.json +3 -3
- package/src/epos-unit.ts +170 -186
package/dist/epos-unit.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type
|
|
1
|
+
import { type Arr, type Ctor, type Log, type Obj } from '@eposlabs/utils';
|
|
2
|
+
import { epos, type Rpc, type RpcTarget } from 'epos';
|
|
3
|
+
export declare const _log_: unique symbol;
|
|
3
4
|
export declare const _root_: unique symbol;
|
|
4
5
|
export declare const _rpcs_: unique symbol;
|
|
5
6
|
export declare const _parent_: unique symbol;
|
|
@@ -12,40 +13,44 @@ export type Versioner<T> = {
|
|
|
12
13
|
[version: number]: (this: T) => void;
|
|
13
14
|
};
|
|
14
15
|
export declare class Unit<TRoot = unknown> {
|
|
15
|
-
/**
|
|
16
|
-
* Lifecycle method called when the unit is attached to the state tree.
|
|
17
|
-
*/
|
|
18
16
|
[epos.state.ATTACH]: () => void;
|
|
19
|
-
/**
|
|
20
|
-
* Lifecycle method called when the unit is detached from the state tree.
|
|
21
|
-
*/
|
|
22
17
|
[epos.state.DETACH]: () => void;
|
|
23
18
|
'@': string;
|
|
24
19
|
id: string;
|
|
25
|
-
log: ReturnType<typeof createLog>;
|
|
26
20
|
[':version']?: number;
|
|
27
|
-
[
|
|
28
|
-
[
|
|
29
|
-
[
|
|
30
|
-
[
|
|
31
|
-
[
|
|
32
|
-
[
|
|
21
|
+
[_log_]: Log | null;
|
|
22
|
+
[_root_]: TRoot | null;
|
|
23
|
+
[_rpcs_]: Record<string, Rpc<RpcTarget>>;
|
|
24
|
+
[_parent_]: Unit<TRoot> | null;
|
|
25
|
+
[_attached_]: boolean;
|
|
26
|
+
[_disposers_]: Set<() => void>;
|
|
27
|
+
[_ancestors_]: Map<Ctor, unknown>;
|
|
33
28
|
[_attachQueue_]?: (() => void)[];
|
|
34
|
-
static defineVersioner<T extends Unit>(this:
|
|
29
|
+
static defineVersioner<T extends Unit>(this: Ctor<T>, versioner: Versioner<T>): Versioner<T>;
|
|
35
30
|
constructor(parent: Unit<TRoot> | null);
|
|
36
31
|
/**
|
|
37
32
|
* Get the root unit of the current unit's tree.
|
|
38
33
|
* The result is cached for subsequent calls.
|
|
39
34
|
*/
|
|
40
|
-
get $(): TRoot
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
get $(): TRoot;
|
|
36
|
+
/**
|
|
37
|
+
* Alternative to `console.*` methods that prefixes all log messages with the unit's name.
|
|
38
|
+
*/
|
|
39
|
+
get log(): Log;
|
|
40
|
+
/**
|
|
41
|
+
* Get access to this unit running by other application instances (tabs, popup, background, etc).
|
|
42
|
+
*/
|
|
43
|
+
use<T extends RpcTarget>(name: string): Rpc<T>;
|
|
43
44
|
/**
|
|
44
|
-
*
|
|
45
|
+
* Expose this unit to be used by other application instances (tabs, popup, background, etc).
|
|
46
|
+
*/
|
|
47
|
+
expose(name: string): void;
|
|
48
|
+
/**
|
|
49
|
+
* A wrapper around MobX's `autorun` that automatically disposes itself when the unit is detached.
|
|
45
50
|
*/
|
|
46
51
|
autorun(...args: Parameters<typeof epos.libs.mobx.autorun>): import("mobx").IReactionDisposer;
|
|
47
52
|
/**
|
|
48
|
-
* A wrapper around MobX's `reaction` that automatically disposes
|
|
53
|
+
* A wrapper around MobX's `reaction` that automatically disposes itself when the unit is detached.
|
|
49
54
|
*/
|
|
50
55
|
reaction(...args: Parameters<typeof epos.libs.mobx.reaction>): import("mobx").IReactionDisposer;
|
|
51
56
|
/**
|
|
@@ -56,13 +61,13 @@ export declare class Unit<TRoot = unknown> {
|
|
|
56
61
|
* A wrapper around `setInterval` that automatically clears the interval when the unit is detached.
|
|
57
62
|
*/
|
|
58
63
|
setInterval(...args: Parameters<typeof setInterval>): NodeJS.Timeout;
|
|
59
|
-
/**
|
|
60
|
-
* Create an error for code paths that are logically unreachable.
|
|
61
|
-
*/
|
|
62
|
-
never(message?: string): Error;
|
|
63
64
|
/**
|
|
64
65
|
* Find the closest ancestor unit of a given type.
|
|
65
66
|
* The result is cached for subsequent calls.
|
|
66
67
|
*/
|
|
67
|
-
closest<T extends Unit>(Ancestor:
|
|
68
|
+
closest<T extends Unit>(Ancestor: Ctor<T>): T | null;
|
|
69
|
+
/**
|
|
70
|
+
* Create an error for code paths that are logically unreachable and should never happen.
|
|
71
|
+
*/
|
|
72
|
+
never(message?: string): Error;
|
|
68
73
|
}
|
package/dist/epos-unit.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
import { createLog, is } from '@eposlabs/utils';
|
|
2
|
+
import { epos } from 'epos';
|
|
3
3
|
import { customAlphabet } from 'nanoid';
|
|
4
|
+
export const _log_ = Symbol('log');
|
|
4
5
|
export const _root_ = Symbol('root');
|
|
5
6
|
export const _rpcs_ = Symbol('rpcs');
|
|
6
7
|
export const _parent_ = Symbol('parent');
|
|
7
8
|
export const _attached_ = Symbol('attached');
|
|
8
9
|
export const _disposers_ = Symbol('disposers');
|
|
9
10
|
export const _ancestors_ = Symbol('ancestors');
|
|
10
|
-
export const _attachQueue_ = Symbol('
|
|
11
|
+
export const _attachQueue_ = Symbol('attachQueue');
|
|
11
12
|
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz0123456789', 10);
|
|
12
13
|
export class Unit {
|
|
13
14
|
static defineVersioner(versioner) {
|
|
@@ -17,170 +18,64 @@ export class Unit {
|
|
|
17
18
|
this.id = nanoid();
|
|
18
19
|
this[_parent_] = parent;
|
|
19
20
|
}
|
|
20
|
-
// ATTACH
|
|
21
|
-
// ---------------------------------------------------------------------------
|
|
22
|
-
/**
|
|
23
|
-
* Lifecycle method called when the unit is attached to the state tree.
|
|
24
|
-
*/
|
|
25
21
|
[epos.state.ATTACH]() {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (!is.object(versioner))
|
|
33
|
-
return;
|
|
34
|
-
const asc = (v1, v2) => v1 - v2;
|
|
35
|
-
const versions = Object.keys(versioner).filter(is.numeric).map(Number).sort(asc);
|
|
36
|
-
if (versions.length === 0)
|
|
37
|
-
return;
|
|
38
|
-
epos.state.transaction(() => {
|
|
39
|
-
for (const version of versions) {
|
|
40
|
-
if (is.number(this[':version']) && this[':version'] >= version)
|
|
41
|
-
continue;
|
|
42
|
-
const versionFn = versioner[version];
|
|
43
|
-
if (!is.function(versionFn))
|
|
44
|
-
continue;
|
|
45
|
-
versionFn.call(this);
|
|
46
|
-
this[':version'] = version;
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
})();
|
|
50
|
-
// Setup state
|
|
51
|
-
void (() => {
|
|
52
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(this.constructor.prototype, 'state');
|
|
53
|
-
if (!descriptor || !descriptor.get)
|
|
54
|
-
return;
|
|
55
|
-
const value = descriptor.get.call(this);
|
|
56
|
-
if (!is.object(value))
|
|
57
|
-
throw new Error(`'state' getter return an object`);
|
|
58
|
-
const state = epos.state.create(value);
|
|
59
|
-
Reflect.defineProperty(state, epos.state.PARENT, { configurable: true, value: this });
|
|
60
|
-
Reflect.defineProperty(this, 'state', { enumerable: true, get: () => state });
|
|
61
|
-
})();
|
|
62
|
-
// Setup inert
|
|
63
|
-
void (() => {
|
|
64
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(this.constructor.prototype, 'inert');
|
|
65
|
-
if (!descriptor || !descriptor.get)
|
|
66
|
-
return;
|
|
67
|
-
const value = descriptor.get.call(this);
|
|
68
|
-
if (!is.object(value))
|
|
69
|
-
throw new Error(`'inert' getter return an object`);
|
|
70
|
-
Reflect.defineProperty(this, 'inert', { enumerable: true, get: () => value });
|
|
71
|
-
})();
|
|
72
|
-
// Prepare properties for the whole prototype chain:
|
|
73
|
-
// - Create components for methods ending with `View`
|
|
74
|
-
// - Bind all other methods to the unit instance
|
|
75
|
-
// - Turn getters into MobX computed properties
|
|
76
|
-
for (const prototype of getPrototypes(this)) {
|
|
77
|
-
const descriptors = Object.getOwnPropertyDescriptors(prototype);
|
|
78
|
-
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
79
|
-
// Skip constructor and already defined properties
|
|
80
|
-
if (key === 'constructor')
|
|
81
|
-
continue;
|
|
82
|
-
if (this.hasOwnProperty(key))
|
|
83
|
-
continue;
|
|
84
|
-
// Create components for methods ending with `View`
|
|
85
|
-
if (is.function(descriptor.value) && key.endsWith('View')) {
|
|
86
|
-
let View = createView(this, key, descriptor.value.bind(this));
|
|
87
|
-
Reflect.defineProperty(this, key, { configurable: true, get: () => View, set: v => (View = v) });
|
|
88
|
-
}
|
|
89
|
-
// Bind all other methods to the unit instance
|
|
90
|
-
else if (is.function(descriptor.value)) {
|
|
91
|
-
let method = descriptor.value.bind(this);
|
|
92
|
-
Reflect.defineProperty(this, key, {
|
|
93
|
-
configurable: true,
|
|
94
|
-
get: () => method,
|
|
95
|
-
set: v => (method = v),
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
// Turn getters into MobX computed properties
|
|
99
|
-
else if (descriptor.get) {
|
|
100
|
-
const getter = descriptor.get;
|
|
101
|
-
const computed = epos.libs.mobx.computed(() => getter.call(this));
|
|
102
|
-
Reflect.defineProperty(this, key, {
|
|
103
|
-
configurable: true,
|
|
104
|
-
get: () => computed.get(),
|
|
105
|
-
set: descriptor.set,
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
// Queue attach method.
|
|
111
|
-
// Do not execute `attach` methods immediately, but rather queue them on the highest unattached ancestor.
|
|
112
|
-
// This way `attach` methods are called after all versioners have been applied in the entire subtree.
|
|
113
|
-
const attach = Reflect.get(this, 'attach');
|
|
114
|
-
if (is.function(attach)) {
|
|
115
|
-
const head = findUnattachedRoot(this);
|
|
116
|
-
if (!head)
|
|
117
|
-
throw this.never();
|
|
118
|
-
ensure(head, _attachQueue_, () => []);
|
|
119
|
-
head[_attachQueue_].push(() => attach.call(this));
|
|
120
|
-
}
|
|
121
|
-
// Release attach queue
|
|
122
|
-
if (this[_attachQueue_]) {
|
|
123
|
-
this[_attachQueue_].forEach(attach => attach());
|
|
124
|
-
delete this[_attachQueue_];
|
|
125
|
-
}
|
|
126
|
-
// Mark as attached
|
|
127
|
-
Reflect.defineProperty(this, _attached_, { configurable: true, get: () => true });
|
|
22
|
+
initInternals(this);
|
|
23
|
+
initVersioner(this);
|
|
24
|
+
initState(this);
|
|
25
|
+
initInert(this);
|
|
26
|
+
enhancePrototype(this);
|
|
27
|
+
scheduleAndFlushAttach(this);
|
|
128
28
|
}
|
|
129
|
-
// DETACH
|
|
130
|
-
// ---------------------------------------------------------------------------
|
|
131
|
-
/**
|
|
132
|
-
* Lifecycle method called when the unit is detached from the state tree.
|
|
133
|
-
*/
|
|
134
29
|
[epos.state.DETACH]() {
|
|
135
|
-
// Run
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
this[_disposers_].clear();
|
|
139
|
-
}
|
|
140
|
-
// Clear ancestors cache
|
|
141
|
-
if (this[_ancestors_]) {
|
|
142
|
-
this[_ancestors_].clear();
|
|
143
|
-
}
|
|
144
|
-
// Call detach method
|
|
30
|
+
// Run disposers
|
|
31
|
+
this[_disposers_].forEach(disposer => disposer());
|
|
32
|
+
// Run detach method
|
|
145
33
|
const detach = Reflect.get(this, 'detach');
|
|
146
34
|
if (is.function(detach))
|
|
147
35
|
detach();
|
|
148
36
|
}
|
|
149
|
-
// ROOT GETTER
|
|
150
|
-
// ---------------------------------------------------------------------------
|
|
151
37
|
/**
|
|
152
38
|
* Get the root unit of the current unit's tree.
|
|
153
39
|
* The result is cached for subsequent calls.
|
|
154
40
|
*/
|
|
155
41
|
get $() {
|
|
156
|
-
|
|
42
|
+
this[_root_] ??= findRoot(this);
|
|
157
43
|
return this[_root_];
|
|
158
44
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
this[
|
|
164
|
-
return this[
|
|
45
|
+
/**
|
|
46
|
+
* Alternative to `console.*` methods that prefixes all log messages with the unit's name.
|
|
47
|
+
*/
|
|
48
|
+
get log() {
|
|
49
|
+
this[_log_] ??= createLog(this['@']);
|
|
50
|
+
return this[_log_];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get access to this unit running by other application instances (tabs, popup, background, etc).
|
|
54
|
+
*/
|
|
55
|
+
use(name) {
|
|
56
|
+
this[_rpcs_][name] ??= epos.bus.use(`${this['@']}[${this.id}][${name}]`);
|
|
57
|
+
return this[_rpcs_][name];
|
|
165
58
|
}
|
|
166
|
-
|
|
167
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Expose this unit to be used by other application instances (tabs, popup, background, etc).
|
|
61
|
+
*/
|
|
62
|
+
expose(name) {
|
|
63
|
+
epos.bus.register(`${this['@']}[${this.id}][${name}]`, this);
|
|
64
|
+
this[_disposers_].add(() => epos.bus.unregister(`${this['@']}[${this.id}][${name}]`));
|
|
168
65
|
}
|
|
169
66
|
/**
|
|
170
|
-
* A wrapper around MobX's `autorun` that automatically disposes
|
|
67
|
+
* A wrapper around MobX's `autorun` that automatically disposes itself when the unit is detached.
|
|
171
68
|
*/
|
|
172
69
|
autorun(...args) {
|
|
173
70
|
const disposer = epos.libs.mobx.autorun(...args);
|
|
174
|
-
ensure(this, _disposers_, () => new Set());
|
|
175
71
|
this[_disposers_].add(disposer);
|
|
176
72
|
return disposer;
|
|
177
73
|
}
|
|
178
74
|
/**
|
|
179
|
-
* A wrapper around MobX's `reaction` that automatically disposes
|
|
75
|
+
* A wrapper around MobX's `reaction` that automatically disposes itself when the unit is detached.
|
|
180
76
|
*/
|
|
181
77
|
reaction(...args) {
|
|
182
78
|
const disposer = epos.libs.mobx.reaction(...args);
|
|
183
|
-
ensure(this, _disposers_, () => new Set());
|
|
184
79
|
this[_disposers_].add(disposer);
|
|
185
80
|
return disposer;
|
|
186
81
|
}
|
|
@@ -189,7 +84,6 @@ export class Unit {
|
|
|
189
84
|
*/
|
|
190
85
|
setTimeout(...args) {
|
|
191
86
|
const id = setTimeout(...args);
|
|
192
|
-
ensure(this, _disposers_, () => new Set());
|
|
193
87
|
this[_disposers_].add(() => clearTimeout(id));
|
|
194
88
|
return id;
|
|
195
89
|
}
|
|
@@ -198,28 +92,18 @@ export class Unit {
|
|
|
198
92
|
*/
|
|
199
93
|
setInterval(...args) {
|
|
200
94
|
const id = setInterval(...args);
|
|
201
|
-
ensure(this, _disposers_, () => new Set());
|
|
202
95
|
this[_disposers_].add(() => clearInterval(id));
|
|
203
96
|
return id;
|
|
204
97
|
}
|
|
205
|
-
/**
|
|
206
|
-
* Create an error for code paths that are logically unreachable.
|
|
207
|
-
*/
|
|
208
|
-
never(message = 'This should never happen') {
|
|
209
|
-
const details = message ? `: ${message}` : '';
|
|
210
|
-
const error = new Error(`[${this['@']}] This should never happen${details}`);
|
|
211
|
-
Error.captureStackTrace(error, this.never);
|
|
212
|
-
return error;
|
|
213
|
-
}
|
|
214
98
|
/**
|
|
215
99
|
* Find the closest ancestor unit of a given type.
|
|
216
100
|
* The result is cached for subsequent calls.
|
|
217
101
|
*/
|
|
218
102
|
closest(Ancestor) {
|
|
219
103
|
// Has cached value? -> Return it
|
|
220
|
-
|
|
221
|
-
if (this[_ancestors_].has(Ancestor))
|
|
104
|
+
if (this[_ancestors_].has(Ancestor)) {
|
|
222
105
|
return this[_ancestors_].get(Ancestor);
|
|
106
|
+
}
|
|
223
107
|
// Find the closest ancestor and cache it
|
|
224
108
|
let cursor = this;
|
|
225
109
|
while (cursor) {
|
|
@@ -231,17 +115,127 @@ export class Unit {
|
|
|
231
115
|
}
|
|
232
116
|
return null;
|
|
233
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Create an error for code paths that are logically unreachable and should never happen.
|
|
120
|
+
*/
|
|
121
|
+
never(message) {
|
|
122
|
+
const details = message ? `: ${message}` : '';
|
|
123
|
+
const error = new Error(`[${this['@']}] SYSTEM FAILURE${details}`);
|
|
124
|
+
Error.captureStackTrace(error, this.never);
|
|
125
|
+
return error;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// MARK: Initialization
|
|
129
|
+
// ============================================================================
|
|
130
|
+
function initInternals(unit) {
|
|
131
|
+
defineAccessor(unit, _log_, null);
|
|
132
|
+
defineAccessor(unit, _root_, null);
|
|
133
|
+
defineAccessor(unit, _rpcs_, {});
|
|
134
|
+
defineAccessor(unit, _attached_, false);
|
|
135
|
+
defineAccessor(unit, _disposers_, new Set());
|
|
136
|
+
defineAccessor(unit, _ancestors_, new Map());
|
|
137
|
+
}
|
|
138
|
+
function initVersioner(unit) {
|
|
139
|
+
const versioner = Reflect.get(unit.constructor, 'versioner');
|
|
140
|
+
if (!is.object(versioner))
|
|
141
|
+
return;
|
|
142
|
+
const asc = (v1, v2) => v1 - v2;
|
|
143
|
+
const versions = Object.keys(versioner).filter(is.numeric).map(Number).sort(asc);
|
|
144
|
+
if (versions.length === 0)
|
|
145
|
+
return;
|
|
146
|
+
epos.state.transaction(() => {
|
|
147
|
+
for (const version of versions) {
|
|
148
|
+
if (is.number(unit[':version']) && unit[':version'] >= version)
|
|
149
|
+
continue;
|
|
150
|
+
const versionFn = versioner[version];
|
|
151
|
+
if (!is.function(versionFn))
|
|
152
|
+
continue;
|
|
153
|
+
versionFn.call(unit);
|
|
154
|
+
unit[':version'] = version;
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
function initState(unit) {
|
|
159
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(unit.constructor.prototype, 'state');
|
|
160
|
+
if (!descriptor || !descriptor.get)
|
|
161
|
+
return;
|
|
162
|
+
const value = descriptor.get.call(unit);
|
|
163
|
+
if (!is.object(value))
|
|
164
|
+
throw new Error(`'state' getter must return an object`);
|
|
165
|
+
const state = epos.state.create(value);
|
|
166
|
+
Reflect.defineProperty(unit, 'state', { get: () => state });
|
|
167
|
+
Reflect.defineProperty(state, epos.state.PARENT, { get: () => unit });
|
|
168
|
+
}
|
|
169
|
+
function initInert(unit) {
|
|
170
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(unit.constructor.prototype, 'inert');
|
|
171
|
+
if (!descriptor || !descriptor.get)
|
|
172
|
+
return;
|
|
173
|
+
const value = descriptor.get.call(unit);
|
|
174
|
+
if (!is.object(value))
|
|
175
|
+
throw new Error(`'inert' getter must return an object`);
|
|
176
|
+
Reflect.defineProperty(unit, 'inert', { get: () => value });
|
|
234
177
|
}
|
|
235
|
-
// HELPERS
|
|
236
|
-
// ---------------------------------------------------------------------------
|
|
237
178
|
/**
|
|
238
|
-
*
|
|
179
|
+
* Prepare properties for the whole prototype chain:
|
|
180
|
+
* - Create components for methods ending with `View`
|
|
181
|
+
* - Bind all other methods to the unit instance
|
|
182
|
+
* - Turn getters into MobX computed properties
|
|
239
183
|
*/
|
|
240
|
-
function
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
184
|
+
function enhancePrototype(unit) {
|
|
185
|
+
for (const prototype of getPrototypes(unit)) {
|
|
186
|
+
const descriptors = Object.getOwnPropertyDescriptors(prototype);
|
|
187
|
+
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
188
|
+
if (key === 'constructor')
|
|
189
|
+
continue;
|
|
190
|
+
if (unit.hasOwnProperty(key))
|
|
191
|
+
continue;
|
|
192
|
+
if (is.function(descriptor.value) && key.endsWith('View')) {
|
|
193
|
+
let View = createComponent(unit, key, descriptor.value.bind(unit));
|
|
194
|
+
Reflect.defineProperty(unit, key, { configurable: true, get: () => View, set: v => (View = v) });
|
|
195
|
+
}
|
|
196
|
+
else if (is.function(descriptor.value)) {
|
|
197
|
+
let method = descriptor.value.bind(unit);
|
|
198
|
+
Reflect.defineProperty(unit, key, { configurable: true, get: () => method, set: v => (method = v) });
|
|
199
|
+
}
|
|
200
|
+
else if (descriptor.get) {
|
|
201
|
+
const getter = descriptor.get;
|
|
202
|
+
const computed = epos.libs.mobx.computed(() => getter.call(unit));
|
|
203
|
+
Reflect.defineProperty(unit, key, { configurable: true, get: () => computed.get(), set: descriptor.set });
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function scheduleAndFlushAttach(unit) {
|
|
209
|
+
// Queue `attach` methods on the highest unattached ancestor (might be self).
|
|
210
|
+
// This way `attach` methods are called after all versioners have been applied in the entire subtree.
|
|
211
|
+
const attach = Reflect.get(unit, 'attach');
|
|
212
|
+
if (is.function(attach)) {
|
|
213
|
+
const head = findUnattachedRoot(unit);
|
|
214
|
+
if (!head)
|
|
215
|
+
throw unit.never();
|
|
216
|
+
const attachQueue = ensureAccessor(head, _attachQueue_, []);
|
|
217
|
+
attachQueue.push(() => attach.call(unit));
|
|
218
|
+
}
|
|
219
|
+
// Release attach queue
|
|
220
|
+
if (unit[_attachQueue_]) {
|
|
221
|
+
unit[_attachQueue_].forEach(attach => attach());
|
|
222
|
+
delete unit[_attachQueue_];
|
|
223
|
+
}
|
|
224
|
+
// Mark as attached
|
|
225
|
+
unit[_attached_] = true;
|
|
226
|
+
}
|
|
227
|
+
// MARK: Helpers
|
|
228
|
+
// ============================================================================
|
|
229
|
+
function defineAccessor(target, key, value) {
|
|
230
|
+
Reflect.defineProperty(target, key, { configurable: true, get: () => value, set: v => (value = v) });
|
|
231
|
+
return value;
|
|
232
|
+
}
|
|
233
|
+
function ensureAccessor(target, key, defaultValue) {
|
|
234
|
+
if (!(key in target))
|
|
235
|
+
defineAccessor(target, key, defaultValue);
|
|
236
|
+
if (!target[key])
|
|
237
|
+
throw new Error(`Failed to ensure accessor for '${String(key)}'`);
|
|
238
|
+
return target[key];
|
|
245
239
|
}
|
|
246
240
|
/**
|
|
247
241
|
* Get all prototypes of an object up to `Object.prototype`.
|
|
@@ -286,11 +280,11 @@ function getParent(node) {
|
|
|
286
280
|
return parent;
|
|
287
281
|
}
|
|
288
282
|
/**
|
|
289
|
-
* Create
|
|
283
|
+
* Create component for the unit.
|
|
290
284
|
*/
|
|
291
|
-
function
|
|
285
|
+
function createComponent(unit, name, render) {
|
|
292
286
|
const fullName = `${unit['@']}.${name}`;
|
|
293
|
-
const
|
|
287
|
+
const Component = epos.component((props) => {
|
|
294
288
|
try {
|
|
295
289
|
return render(props);
|
|
296
290
|
}
|
|
@@ -311,7 +305,7 @@ function createView(unit, name, render) {
|
|
|
311
305
|
});
|
|
312
306
|
}
|
|
313
307
|
});
|
|
314
|
-
|
|
315
|
-
return
|
|
308
|
+
Component.displayName = fullName;
|
|
309
|
+
return Component;
|
|
316
310
|
}
|
|
317
311
|
//# sourceMappingURL=epos-unit.js.map
|
package/dist/epos-unit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"epos-unit.js","sourceRoot":"","sources":["../src/epos-unit.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,OAAO,EAAE,SAAS,EAAE,EAAE,EAAgC,MAAM,eAAe,CAAA;AAE3E,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAA;AAGvC,MAAM,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;AACpC,MAAM,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;AACpC,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAA;AACxC,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,CAAA;AAC5C,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC,CAAA;AAC9C,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC,CAAA;AAC9C,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,oBAAoB,CAAC,C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aAAa;oBACpB,OAAO,EAAE,iBAAiB;oBAC1B,KAAK,EAAE,MAAM;oBACb,MAAM,EAAE,gBAAgB;oBACxB,UAAU,EAAE,sBAAsB;oBAClC,QAAQ,EAAE,EAAE;oBACZ,UAAU,EAAE,GAAG;iBAChB;aACF,CAAC,CAAA;QACJ,CAAC;IAAA,CACF,CAAC,CAAA;IAEF,SAAS,CAAC,WAAW,GAAG,QAAQ,CAAA;IAEhC,OAAO,SAAS,CAAA;AAAA,CACjB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "epos-unit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.27.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "imkost",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"src"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"
|
|
23
|
-
"epos": "^1.
|
|
22
|
+
"@eposlabs/utils": "^1.22.0",
|
|
23
|
+
"epos": "^1.57.0",
|
|
24
24
|
"nanoid": "^5.1.6"
|
|
25
25
|
}
|
|
26
26
|
}
|
package/src/epos-unit.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import type { Asyncify } from 'epos'
|
|
1
|
+
import { createLog, is, type Arr, type Ctor, type Log, type Obj } from '@eposlabs/utils'
|
|
2
|
+
import { epos, type Rpc, type RpcTarget } from 'epos'
|
|
4
3
|
import { customAlphabet } from 'nanoid'
|
|
5
4
|
import type { FC } from 'react'
|
|
6
5
|
|
|
6
|
+
export const _log_ = Symbol('log')
|
|
7
7
|
export const _root_ = Symbol('root')
|
|
8
8
|
export const _rpcs_ = Symbol('rpcs')
|
|
9
9
|
export const _parent_ = Symbol('parent')
|
|
10
10
|
export const _attached_ = Symbol('attached')
|
|
11
11
|
export const _disposers_ = Symbol('disposers')
|
|
12
12
|
export const _ancestors_ = Symbol('ancestors')
|
|
13
|
-
export const _attachQueue_ = Symbol('
|
|
13
|
+
export const _attachQueue_ = Symbol('attachQueue')
|
|
14
14
|
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz0123456789', 10)
|
|
15
15
|
|
|
16
16
|
export type Node<T> = Unit<T> | Obj | Arr
|
|
@@ -18,18 +18,18 @@ export type Versioner<T> = { [version: number]: (this: T) => void }
|
|
|
18
18
|
|
|
19
19
|
export class Unit<TRoot = unknown> {
|
|
20
20
|
declare '@': string
|
|
21
|
-
declare id: string
|
|
22
|
-
declare log: ReturnType<typeof createLog>;
|
|
21
|
+
declare id: string;
|
|
23
22
|
declare [':version']?: number;
|
|
24
|
-
declare [
|
|
25
|
-
declare [
|
|
26
|
-
declare [
|
|
27
|
-
declare [
|
|
28
|
-
declare [
|
|
29
|
-
declare [
|
|
23
|
+
declare [_log_]: Log | null;
|
|
24
|
+
declare [_root_]: TRoot | null;
|
|
25
|
+
declare [_rpcs_]: Record<string, Rpc<RpcTarget>>;
|
|
26
|
+
declare [_parent_]: Unit<TRoot> | null; // Parent reference for a not-yet-attached units
|
|
27
|
+
declare [_attached_]: boolean;
|
|
28
|
+
declare [_disposers_]: Set<() => void>;
|
|
29
|
+
declare [_ancestors_]: Map<Ctor, unknown>;
|
|
30
30
|
declare [_attachQueue_]?: (() => void)[]
|
|
31
31
|
|
|
32
|
-
static defineVersioner<T extends Unit>(this:
|
|
32
|
+
static defineVersioner<T extends Unit>(this: Ctor<T>, versioner: Versioner<T>) {
|
|
33
33
|
return versioner
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -38,182 +38,71 @@ export class Unit<TRoot = unknown> {
|
|
|
38
38
|
this[_parent_] = parent
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
// ATTACH
|
|
42
|
-
// ---------------------------------------------------------------------------
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Lifecycle method called when the unit is attached to the state tree.
|
|
46
|
-
*/
|
|
47
41
|
[epos.state.ATTACH]() {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const versioner: unknown = Reflect.get(this.constructor, 'versioner')
|
|
55
|
-
if (!is.object(versioner)) return
|
|
56
|
-
|
|
57
|
-
const asc = (v1: number, v2: number) => v1 - v2
|
|
58
|
-
const versions = Object.keys(versioner).filter(is.numeric).map(Number).sort(asc)
|
|
59
|
-
if (versions.length === 0) return
|
|
60
|
-
|
|
61
|
-
epos.state.transaction(() => {
|
|
62
|
-
for (const version of versions) {
|
|
63
|
-
if (is.number(this[':version']) && this[':version'] >= version) continue
|
|
64
|
-
const versionFn = versioner[version]
|
|
65
|
-
if (!is.function(versionFn)) continue
|
|
66
|
-
versionFn.call(this)
|
|
67
|
-
this[':version'] = version
|
|
68
|
-
}
|
|
69
|
-
})
|
|
70
|
-
})()
|
|
71
|
-
|
|
72
|
-
// Setup state
|
|
73
|
-
void (() => {
|
|
74
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(this.constructor.prototype, 'state')
|
|
75
|
-
if (!descriptor || !descriptor.get) return
|
|
76
|
-
const value: unknown = descriptor.get.call(this)
|
|
77
|
-
if (!is.object(value)) throw new Error(`'state' getter return an object`)
|
|
78
|
-
const state = epos.state.create(value)
|
|
79
|
-
Reflect.defineProperty(state, epos.state.PARENT, { configurable: true, value: this })
|
|
80
|
-
Reflect.defineProperty(this, 'state', { enumerable: true, get: () => state })
|
|
81
|
-
})()
|
|
82
|
-
|
|
83
|
-
// Setup inert
|
|
84
|
-
void (() => {
|
|
85
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(this.constructor.prototype, 'inert')
|
|
86
|
-
if (!descriptor || !descriptor.get) return
|
|
87
|
-
const value: unknown = descriptor.get.call(this)
|
|
88
|
-
if (!is.object(value)) throw new Error(`'inert' getter return an object`)
|
|
89
|
-
Reflect.defineProperty(this, 'inert', { enumerable: true, get: () => value })
|
|
90
|
-
})()
|
|
91
|
-
|
|
92
|
-
// Prepare properties for the whole prototype chain:
|
|
93
|
-
// - Create components for methods ending with `View`
|
|
94
|
-
// - Bind all other methods to the unit instance
|
|
95
|
-
// - Turn getters into MobX computed properties
|
|
96
|
-
for (const prototype of getPrototypes(this)) {
|
|
97
|
-
const descriptors = Object.getOwnPropertyDescriptors(prototype)
|
|
98
|
-
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
99
|
-
// Skip constructor and already defined properties
|
|
100
|
-
if (key === 'constructor') continue
|
|
101
|
-
if (this.hasOwnProperty(key)) continue
|
|
102
|
-
|
|
103
|
-
// Create components for methods ending with `View`
|
|
104
|
-
if (is.function(descriptor.value) && key.endsWith('View')) {
|
|
105
|
-
let View = createView(this, key, descriptor.value.bind(this) as FC<unknown>)
|
|
106
|
-
Reflect.defineProperty(this, key, { configurable: true, get: () => View, set: v => (View = v) })
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Bind all other methods to the unit instance
|
|
110
|
-
else if (is.function(descriptor.value)) {
|
|
111
|
-
let method = descriptor.value.bind(this)
|
|
112
|
-
Reflect.defineProperty(this, key, {
|
|
113
|
-
configurable: true,
|
|
114
|
-
get: () => method,
|
|
115
|
-
set: v => (method = v),
|
|
116
|
-
})
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Turn getters into MobX computed properties
|
|
120
|
-
else if (descriptor.get) {
|
|
121
|
-
const getter = descriptor.get
|
|
122
|
-
const computed = epos.libs.mobx.computed(() => getter.call(this))
|
|
123
|
-
Reflect.defineProperty(this, key, {
|
|
124
|
-
configurable: true,
|
|
125
|
-
get: () => computed.get(),
|
|
126
|
-
set: descriptor.set,
|
|
127
|
-
})
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Queue attach method.
|
|
133
|
-
// Do not execute `attach` methods immediately, but rather queue them on the highest unattached ancestor.
|
|
134
|
-
// This way `attach` methods are called after all versioners have been applied in the entire subtree.
|
|
135
|
-
const attach = Reflect.get(this, 'attach')
|
|
136
|
-
if (is.function(attach)) {
|
|
137
|
-
const head = findUnattachedRoot(this)
|
|
138
|
-
if (!head) throw this.never()
|
|
139
|
-
ensure(head, _attachQueue_, () => [])
|
|
140
|
-
head[_attachQueue_].push(() => attach.call(this))
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Release attach queue
|
|
144
|
-
if (this[_attachQueue_]) {
|
|
145
|
-
this[_attachQueue_].forEach(attach => attach())
|
|
146
|
-
delete this[_attachQueue_]
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Mark as attached
|
|
150
|
-
Reflect.defineProperty(this, _attached_, { configurable: true, get: () => true })
|
|
42
|
+
initInternals(this)
|
|
43
|
+
initVersioner(this)
|
|
44
|
+
initState(this)
|
|
45
|
+
initInert(this)
|
|
46
|
+
enhancePrototype(this)
|
|
47
|
+
scheduleAndFlushAttach(this)
|
|
151
48
|
}
|
|
152
49
|
|
|
153
|
-
// DETACH
|
|
154
|
-
// ---------------------------------------------------------------------------
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Lifecycle method called when the unit is detached from the state tree.
|
|
158
|
-
*/
|
|
159
50
|
[epos.state.DETACH]() {
|
|
160
|
-
// Run
|
|
161
|
-
|
|
162
|
-
this[_disposers_].forEach(disposer => disposer())
|
|
163
|
-
this[_disposers_].clear()
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// Clear ancestors cache
|
|
167
|
-
if (this[_ancestors_]) {
|
|
168
|
-
this[_ancestors_].clear()
|
|
169
|
-
}
|
|
51
|
+
// Run disposers
|
|
52
|
+
this[_disposers_].forEach(disposer => disposer())
|
|
170
53
|
|
|
171
|
-
//
|
|
54
|
+
// Run detach method
|
|
172
55
|
const detach = Reflect.get(this, 'detach')
|
|
173
56
|
if (is.function(detach)) detach()
|
|
174
57
|
}
|
|
175
58
|
|
|
176
|
-
// ROOT GETTER
|
|
177
|
-
// ---------------------------------------------------------------------------
|
|
178
|
-
|
|
179
59
|
/**
|
|
180
60
|
* Get the root unit of the current unit's tree.
|
|
181
61
|
* The result is cached for subsequent calls.
|
|
182
62
|
*/
|
|
183
63
|
get $() {
|
|
184
|
-
|
|
64
|
+
this[_root_] ??= findRoot(this)
|
|
185
65
|
return this[_root_]
|
|
186
66
|
}
|
|
187
67
|
|
|
188
|
-
|
|
189
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Alternative to `console.*` methods that prefixes all log messages with the unit's name.
|
|
70
|
+
*/
|
|
71
|
+
get log() {
|
|
72
|
+
this[_log_] ??= createLog(this['@'])
|
|
73
|
+
return this[_log_]
|
|
74
|
+
}
|
|
190
75
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Get access to this unit running by other application instances (tabs, popup, background, etc).
|
|
78
|
+
*/
|
|
79
|
+
use<T extends RpcTarget>(name: string): Rpc<T> {
|
|
80
|
+
this[_rpcs_][name] ??= epos.bus.use<T>(`${this['@']}[${this.id}][${name}]`)
|
|
81
|
+
return this[_rpcs_][name]
|
|
195
82
|
}
|
|
196
83
|
|
|
197
|
-
|
|
198
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Expose this unit to be used by other application instances (tabs, popup, background, etc).
|
|
86
|
+
*/
|
|
87
|
+
expose(name: string) {
|
|
88
|
+
epos.bus.register(`${this['@']}[${this.id}][${name}]`, this)
|
|
89
|
+
this[_disposers_].add(() => epos.bus.unregister(`${this['@']}[${this.id}][${name}]`))
|
|
199
90
|
}
|
|
200
91
|
|
|
201
92
|
/**
|
|
202
|
-
* A wrapper around MobX's `autorun` that automatically disposes
|
|
93
|
+
* A wrapper around MobX's `autorun` that automatically disposes itself when the unit is detached.
|
|
203
94
|
*/
|
|
204
95
|
autorun(...args: Parameters<typeof epos.libs.mobx.autorun>) {
|
|
205
96
|
const disposer = epos.libs.mobx.autorun(...args)
|
|
206
|
-
ensure(this, _disposers_, () => new Set())
|
|
207
97
|
this[_disposers_].add(disposer)
|
|
208
98
|
return disposer
|
|
209
99
|
}
|
|
210
100
|
|
|
211
101
|
/**
|
|
212
|
-
* A wrapper around MobX's `reaction` that automatically disposes
|
|
102
|
+
* A wrapper around MobX's `reaction` that automatically disposes itself when the unit is detached.
|
|
213
103
|
*/
|
|
214
104
|
reaction(...args: Parameters<typeof epos.libs.mobx.reaction>) {
|
|
215
105
|
const disposer = epos.libs.mobx.reaction(...args)
|
|
216
|
-
ensure(this, _disposers_, () => new Set())
|
|
217
106
|
this[_disposers_].add(disposer)
|
|
218
107
|
return disposer
|
|
219
108
|
}
|
|
@@ -223,7 +112,6 @@ export class Unit<TRoot = unknown> {
|
|
|
223
112
|
*/
|
|
224
113
|
setTimeout(...args: Parameters<typeof setTimeout>) {
|
|
225
114
|
const id = setTimeout(...args)
|
|
226
|
-
ensure(this, _disposers_, () => new Set())
|
|
227
115
|
this[_disposers_].add(() => clearTimeout(id))
|
|
228
116
|
return id
|
|
229
117
|
}
|
|
@@ -233,29 +121,19 @@ export class Unit<TRoot = unknown> {
|
|
|
233
121
|
*/
|
|
234
122
|
setInterval(...args: Parameters<typeof setInterval>) {
|
|
235
123
|
const id = setInterval(...args)
|
|
236
|
-
ensure(this, _disposers_, () => new Set())
|
|
237
124
|
this[_disposers_].add(() => clearInterval(id))
|
|
238
125
|
return id
|
|
239
126
|
}
|
|
240
127
|
|
|
241
|
-
/**
|
|
242
|
-
* Create an error for code paths that are logically unreachable.
|
|
243
|
-
*/
|
|
244
|
-
never(message = 'This should never happen') {
|
|
245
|
-
const details = message ? `: ${message}` : ''
|
|
246
|
-
const error = new Error(`[${this['@']}] This should never happen${details}`)
|
|
247
|
-
Error.captureStackTrace(error, this.never)
|
|
248
|
-
return error
|
|
249
|
-
}
|
|
250
|
-
|
|
251
128
|
/**
|
|
252
129
|
* Find the closest ancestor unit of a given type.
|
|
253
130
|
* The result is cached for subsequent calls.
|
|
254
131
|
*/
|
|
255
|
-
closest<T extends Unit>(Ancestor:
|
|
132
|
+
closest<T extends Unit>(Ancestor: Ctor<T>) {
|
|
256
133
|
// Has cached value? -> Return it
|
|
257
|
-
|
|
258
|
-
|
|
134
|
+
if (this[_ancestors_].has(Ancestor)) {
|
|
135
|
+
return this[_ancestors_].get(Ancestor) as T
|
|
136
|
+
}
|
|
259
137
|
|
|
260
138
|
// Find the closest ancestor and cache it
|
|
261
139
|
let cursor: Node<TRoot> | null = this
|
|
@@ -269,22 +147,128 @@ export class Unit<TRoot = unknown> {
|
|
|
269
147
|
|
|
270
148
|
return null
|
|
271
149
|
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Create an error for code paths that are logically unreachable and should never happen.
|
|
153
|
+
*/
|
|
154
|
+
never(message?: string) {
|
|
155
|
+
const details = message ? `: ${message}` : ''
|
|
156
|
+
const error = new Error(`[${this['@']}] SYSTEM FAILURE${details}`)
|
|
157
|
+
Error.captureStackTrace(error, this.never)
|
|
158
|
+
return error
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// MARK: Initialization
|
|
163
|
+
// ============================================================================
|
|
164
|
+
|
|
165
|
+
function initInternals<T>(unit: Unit<T>) {
|
|
166
|
+
defineAccessor(unit, _log_, null)
|
|
167
|
+
defineAccessor(unit, _root_, null)
|
|
168
|
+
defineAccessor(unit, _rpcs_, {})
|
|
169
|
+
defineAccessor(unit, _attached_, false)
|
|
170
|
+
defineAccessor(unit, _disposers_, new Set())
|
|
171
|
+
defineAccessor(unit, _ancestors_, new Map())
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function initVersioner<T>(unit: Unit<T>) {
|
|
175
|
+
const versioner: unknown = Reflect.get(unit.constructor, 'versioner')
|
|
176
|
+
if (!is.object(versioner)) return
|
|
177
|
+
|
|
178
|
+
const asc = (v1: number, v2: number) => v1 - v2
|
|
179
|
+
const versions = Object.keys(versioner).filter(is.numeric).map(Number).sort(asc)
|
|
180
|
+
if (versions.length === 0) return
|
|
181
|
+
|
|
182
|
+
epos.state.transaction(() => {
|
|
183
|
+
for (const version of versions) {
|
|
184
|
+
if (is.number(unit[':version']) && unit[':version'] >= version) continue
|
|
185
|
+
const versionFn = (versioner as any)[version]
|
|
186
|
+
if (!is.function(versionFn)) continue
|
|
187
|
+
versionFn.call(unit)
|
|
188
|
+
unit[':version'] = version
|
|
189
|
+
}
|
|
190
|
+
})
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function initState<T>(unit: Unit<T>) {
|
|
194
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(unit.constructor.prototype, 'state')
|
|
195
|
+
if (!descriptor || !descriptor.get) return
|
|
196
|
+
const value: unknown = descriptor.get.call(unit)
|
|
197
|
+
if (!is.object(value)) throw new Error(`'state' getter must return an object`)
|
|
198
|
+
const state = epos.state.create(value)
|
|
199
|
+
Reflect.defineProperty(unit, 'state', { get: () => state })
|
|
200
|
+
Reflect.defineProperty(state, epos.state.PARENT, { get: () => unit })
|
|
272
201
|
}
|
|
273
202
|
|
|
274
|
-
|
|
275
|
-
|
|
203
|
+
function initInert<T>(unit: Unit<T>) {
|
|
204
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(unit.constructor.prototype, 'inert')
|
|
205
|
+
if (!descriptor || !descriptor.get) return
|
|
206
|
+
const value: unknown = descriptor.get.call(unit)
|
|
207
|
+
if (!is.object(value)) throw new Error(`'inert' getter must return an object`)
|
|
208
|
+
Reflect.defineProperty(unit, 'inert', { get: () => value })
|
|
209
|
+
}
|
|
276
210
|
|
|
277
211
|
/**
|
|
278
|
-
*
|
|
212
|
+
* Prepare properties for the whole prototype chain:
|
|
213
|
+
* - Create components for methods ending with `View`
|
|
214
|
+
* - Bind all other methods to the unit instance
|
|
215
|
+
* - Turn getters into MobX computed properties
|
|
279
216
|
*/
|
|
280
|
-
function
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
217
|
+
function enhancePrototype<T>(unit: Unit<T>) {
|
|
218
|
+
for (const prototype of getPrototypes(unit)) {
|
|
219
|
+
const descriptors = Object.getOwnPropertyDescriptors(prototype)
|
|
220
|
+
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
221
|
+
if (key === 'constructor') continue
|
|
222
|
+
if (unit.hasOwnProperty(key)) continue
|
|
223
|
+
|
|
224
|
+
if (is.function(descriptor.value) && key.endsWith('View')) {
|
|
225
|
+
let View = createComponent(unit, key, descriptor.value.bind(unit) as FC<unknown>)
|
|
226
|
+
Reflect.defineProperty(unit, key, { configurable: true, get: () => View, set: v => (View = v) })
|
|
227
|
+
} else if (is.function(descriptor.value)) {
|
|
228
|
+
let method = descriptor.value.bind(unit)
|
|
229
|
+
Reflect.defineProperty(unit, key, { configurable: true, get: () => method, set: v => (method = v) })
|
|
230
|
+
} else if (descriptor.get) {
|
|
231
|
+
const getter = descriptor.get
|
|
232
|
+
const computed = epos.libs.mobx.computed(() => getter.call(unit))
|
|
233
|
+
Reflect.defineProperty(unit, key, { configurable: true, get: () => computed.get(), set: descriptor.set })
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function scheduleAndFlushAttach<T>(unit: Unit<T>) {
|
|
240
|
+
// Queue `attach` methods on the highest unattached ancestor (might be self).
|
|
241
|
+
// This way `attach` methods are called after all versioners have been applied in the entire subtree.
|
|
242
|
+
const attach = Reflect.get(unit, 'attach')
|
|
243
|
+
if (is.function(attach)) {
|
|
244
|
+
const head = findUnattachedRoot(unit)
|
|
245
|
+
if (!head) throw unit.never()
|
|
246
|
+
const attachQueue = ensureAccessor(head, _attachQueue_, [])
|
|
247
|
+
attachQueue.push(() => attach.call(unit))
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Release attach queue
|
|
251
|
+
if (unit[_attachQueue_]) {
|
|
252
|
+
unit[_attachQueue_].forEach(attach => attach())
|
|
253
|
+
delete unit[_attachQueue_]
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Mark as attached
|
|
257
|
+
unit[_attached_] = true
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// MARK: Helpers
|
|
261
|
+
// ============================================================================
|
|
262
|
+
|
|
263
|
+
function defineAccessor<T extends object, K extends keyof T>(target: T, key: K, value: T[K]) {
|
|
264
|
+
Reflect.defineProperty(target, key, { configurable: true, get: () => value, set: v => (value = v) })
|
|
265
|
+
return value
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function ensureAccessor<T extends object, K extends keyof T>(target: T, key: K, defaultValue: T[K]) {
|
|
269
|
+
if (!(key in target)) defineAccessor(target, key, defaultValue)
|
|
270
|
+
if (!target[key]) throw new Error(`Failed to ensure accessor for '${String(key)}'`)
|
|
271
|
+
return target[key]
|
|
288
272
|
}
|
|
289
273
|
|
|
290
274
|
/**
|
|
@@ -335,12 +319,12 @@ function getParent<T>(node: Node<T>) {
|
|
|
335
319
|
}
|
|
336
320
|
|
|
337
321
|
/**
|
|
338
|
-
* Create
|
|
322
|
+
* Create component for the unit.
|
|
339
323
|
*/
|
|
340
|
-
function
|
|
324
|
+
function createComponent<T>(unit: Unit<T>, name: string, render: FC<unknown>) {
|
|
341
325
|
const fullName = `${unit['@']}.${name}`
|
|
342
326
|
|
|
343
|
-
const
|
|
327
|
+
const Component = epos.component((props: unknown) => {
|
|
344
328
|
try {
|
|
345
329
|
return render(props)
|
|
346
330
|
} catch (error) {
|
|
@@ -361,7 +345,7 @@ function createView<T>(unit: Unit<T>, name: string, render: FC<unknown>) {
|
|
|
361
345
|
}
|
|
362
346
|
})
|
|
363
347
|
|
|
364
|
-
|
|
348
|
+
Component.displayName = fullName
|
|
365
349
|
|
|
366
|
-
return
|
|
350
|
+
return Component
|
|
367
351
|
}
|