mani-game-engine 1.0.0-pre.5 → 1.0.0-pre.51
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/LICENSE +21 -21
- package/README.md +69 -69
- package/lib/clock.d.ts +55 -31
- package/lib/clock.js +117 -78
- package/lib/clock.js.map +1 -1
- package/lib/ecsInjector.d.ts +46 -24
- package/lib/ecsInjector.js +222 -138
- package/lib/ecsInjector.js.map +1 -1
- package/lib/entity.d.ts +35 -21
- package/lib/entity.js +167 -85
- package/lib/entity.js.map +1 -1
- package/lib/gameEngine.d.ts +89 -76
- package/lib/gameEngine.js +368 -316
- package/lib/gameEngine.js.map +1 -1
- package/lib/index.d.ts +12 -10
- package/lib/index.js +35 -10
- package/lib/index.js.map +1 -1
- package/lib/injector.d.ts +130 -0
- package/lib/injector.js +324 -0
- package/lib/injector.js.map +1 -0
- package/lib/scope/scopeContext.d.ts +71 -53
- package/lib/scope/scopeContext.js +297 -206
- package/lib/scope/scopeContext.js.map +1 -1
- package/lib/systemContext.d.ts +15 -11
- package/lib/systemContext.js +38 -16
- package/lib/systemContext.js.map +1 -1
- package/lib/types.d.ts +83 -67
- package/lib/types.js +19 -9
- package/lib/types.js.map +1 -1
- package/lib/utils/map2k.d.ts +6 -6
- package/lib/utils/map2k.js +43 -39
- package/lib/utils/map2k.js.map +1 -1
- package/package.json +39 -40
- package/src/clock.ts +163 -103
- package/src/ecsInjector.ts +279 -183
- package/src/entity.ts +202 -116
- package/src/gameEngine.ts +472 -411
- package/src/index.ts +33 -14
- package/src/injector.ts +410 -0
- package/src/scope/scopeContext.ts +380 -267
- package/src/systemContext.ts +40 -22
- package/src/types.ts +99 -82
- package/src/utils/map2k.ts +52 -52
|
@@ -1,53 +1,71 @@
|
|
|
1
|
-
import { Class, EcsInjector, Signal } from '../index';
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
4
|
-
keepAlive?: boolean | Scope[];
|
|
5
|
-
group?: string;
|
|
6
|
-
};
|
|
7
|
-
export declare const scopeSignalHandlers: Map<Object, [string,
|
|
8
|
-
export declare const OnScopeSignal: (id:
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
private
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
private
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
1
|
+
import { Class, EcsInjector, Signal, SignalCallback } from '../index';
|
|
2
|
+
import { ID } from '../injector';
|
|
3
|
+
export type ScopeSignalOptions = {
|
|
4
|
+
keepAlive?: boolean | Scope[];
|
|
5
|
+
group?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const scopeSignalHandlers: Map<Object, [string, ID, (ScopeSignalOptions | undefined)?][]>;
|
|
8
|
+
export declare const OnScopeSignal: (id: ID, options?: ScopeSignalOptions) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
9
|
+
export declare const SCOPE_CONTEXT: {
|
|
10
|
+
log: boolean;
|
|
11
|
+
};
|
|
12
|
+
export interface Scope {
|
|
13
|
+
[propName: string]: any;
|
|
14
|
+
onEnter?(): void;
|
|
15
|
+
onExit?(): void;
|
|
16
|
+
onSubReturn?(): void;
|
|
17
|
+
onSubExit?(): void;
|
|
18
|
+
onActivate?(): void;
|
|
19
|
+
onDeactivate?(): void;
|
|
20
|
+
}
|
|
21
|
+
export type ScopeMapping = (params: {
|
|
22
|
+
injector: EcsInjector;
|
|
23
|
+
registerScopeService: (serviceClass: Class) => void;
|
|
24
|
+
onEnter: Signal<ScopeContext>;
|
|
25
|
+
onExit: Signal<ScopeContext>;
|
|
26
|
+
onSubReturn: Signal<ScopeContext>;
|
|
27
|
+
onSubExit: Signal<ScopeContext>;
|
|
28
|
+
onActivate: Signal<ScopeContext>;
|
|
29
|
+
onDeactivate: Signal<ScopeContext>;
|
|
30
|
+
}) => any | Promise<void>;
|
|
31
|
+
interface AddScopeSignalOptions extends ScopeSignalOptions {
|
|
32
|
+
context?: unknown;
|
|
33
|
+
}
|
|
34
|
+
export declare class ScopeContext {
|
|
35
|
+
private parent?;
|
|
36
|
+
readonly scope: Scope;
|
|
37
|
+
readonly injector: EcsInjector;
|
|
38
|
+
private readonly stack;
|
|
39
|
+
private readonly signalBindings;
|
|
40
|
+
private serviceBindings;
|
|
41
|
+
private closed;
|
|
42
|
+
private muteKeepAliveSignals;
|
|
43
|
+
readonly onEnter: Signal<ScopeContext>;
|
|
44
|
+
readonly onExit: Signal<ScopeContext>;
|
|
45
|
+
readonly onSubReturn: Signal<ScopeContext>;
|
|
46
|
+
readonly onSubExit: Signal<ScopeContext>;
|
|
47
|
+
readonly onActivate: Signal<ScopeContext>;
|
|
48
|
+
readonly onDeactivate: Signal<ScopeContext>;
|
|
49
|
+
private readonly creationTime;
|
|
50
|
+
get runtime(): number;
|
|
51
|
+
constructor(injector: EcsInjector, scopeClass: Class, mapping?: ScopeMapping, parent?: ScopeContext | undefined, resolve?: () => void);
|
|
52
|
+
get isRoot(): boolean;
|
|
53
|
+
get target(): Scope | undefined;
|
|
54
|
+
get isActive(): boolean;
|
|
55
|
+
get activeContext(): ScopeContext;
|
|
56
|
+
enterScope(scopeClass: Class, mapping?: ScopeMapping): Promise<ScopeContext | undefined>;
|
|
57
|
+
exitScope(target?: Scope): Promise<void>;
|
|
58
|
+
closeSubScopes(): void;
|
|
59
|
+
private logStack;
|
|
60
|
+
getStackClasses(): Scope[];
|
|
61
|
+
addScopeSignal<T>(signal: Signal<T>, callback: SignalCallback<T>, params?: AddScopeSignalOptions): void;
|
|
62
|
+
disableKeepAliveSignals(): void;
|
|
63
|
+
enableKeepAliveSignals(): void;
|
|
64
|
+
private updateSignalBindings;
|
|
65
|
+
private detachSignalBindings;
|
|
66
|
+
private mapScopeSignals;
|
|
67
|
+
private mapServiceSignals;
|
|
68
|
+
private detachServiceBindings;
|
|
69
|
+
private exitThis;
|
|
70
|
+
}
|
|
71
|
+
export {};
|
|
@@ -1,207 +1,298 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
this.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
this.
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
this.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
this.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.
|
|
59
|
-
this.
|
|
60
|
-
this.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
this.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
if (
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ScopeContext = exports.SCOPE_CONTEXT = exports.OnScopeSignal = exports.scopeSignalHandlers = void 0;
|
|
4
|
+
const index_1 = require("../index");
|
|
5
|
+
const ecsInjector_1 = require("../ecsInjector");
|
|
6
|
+
const injector_1 = require("../injector");
|
|
7
|
+
exports.scopeSignalHandlers = new Map();
|
|
8
|
+
const OnScopeSignal = (id, options) => (target, propertyKey, descriptor) => {
|
|
9
|
+
if (target instanceof Function) {
|
|
10
|
+
throw new Error('only allowed on non static methods');
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
const mappingList = (0, injector_1.putIfAbsent)(exports.scopeSignalHandlers, target.constructor, () => []);
|
|
14
|
+
mappingList.push([propertyKey, id, options]);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
exports.OnScopeSignal = OnScopeSignal;
|
|
18
|
+
exports.SCOPE_CONTEXT = {
|
|
19
|
+
log: true,
|
|
20
|
+
};
|
|
21
|
+
class ScopeSignalBinding {
|
|
22
|
+
constructor(signalBinding, options) {
|
|
23
|
+
this.signalBinding = signalBinding;
|
|
24
|
+
this.keepAlive = options === null || options === void 0 ? void 0 : options.keepAlive;
|
|
25
|
+
this.group = options === null || options === void 0 ? void 0 : options.group;
|
|
26
|
+
}
|
|
27
|
+
activate() {
|
|
28
|
+
this.signalBinding.setActive(true);
|
|
29
|
+
}
|
|
30
|
+
deactivate() {
|
|
31
|
+
this.signalBinding.setActive(false);
|
|
32
|
+
}
|
|
33
|
+
detach() {
|
|
34
|
+
this.signalBinding.detach();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
class ScopeStack {
|
|
38
|
+
constructor(rootScope) {
|
|
39
|
+
this.rootScope = rootScope;
|
|
40
|
+
this.stack = [];
|
|
41
|
+
this.queuedScopeChanges = [];
|
|
42
|
+
this.ongoingChange = false;
|
|
43
|
+
this.stack.push(rootScope);
|
|
44
|
+
}
|
|
45
|
+
get rootContext() {
|
|
46
|
+
return this.stack[0];
|
|
47
|
+
}
|
|
48
|
+
get activeContext() {
|
|
49
|
+
return this.stack[this.stack.length - 1];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
class ScopeContext {
|
|
53
|
+
get runtime() {
|
|
54
|
+
return (performance.now() - this.creationTime) / 1000;
|
|
55
|
+
}
|
|
56
|
+
constructor(injector, scopeClass, mapping, parent, resolve) {
|
|
57
|
+
this.parent = parent;
|
|
58
|
+
this.signalBindings = [];
|
|
59
|
+
this.serviceBindings = [];
|
|
60
|
+
this.closed = false;
|
|
61
|
+
this.muteKeepAliveSignals = false;
|
|
62
|
+
this.onEnter = new index_1.Signal();
|
|
63
|
+
this.onExit = new index_1.Signal();
|
|
64
|
+
this.onSubReturn = new index_1.Signal();
|
|
65
|
+
this.onSubExit = new index_1.Signal();
|
|
66
|
+
this.onActivate = new index_1.Signal();
|
|
67
|
+
this.onDeactivate = new index_1.Signal();
|
|
68
|
+
this.creationTime = performance.now();
|
|
69
|
+
if (!parent) {
|
|
70
|
+
this.stack = new ScopeStack(this);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
this.stack = parent.stack;
|
|
74
|
+
this.stack.stack.push(this);
|
|
75
|
+
}
|
|
76
|
+
this.injector = injector.createChild();
|
|
77
|
+
this.injector.map(scopeClass).toSingleton();
|
|
78
|
+
this.injector.map(ScopeContext).toValue(this);
|
|
79
|
+
const result = mapping === null || mapping === void 0 ? void 0 : mapping({
|
|
80
|
+
injector: this.injector,
|
|
81
|
+
registerScopeService: serviceClass => {
|
|
82
|
+
this.injector.map(serviceClass).toSingleton();
|
|
83
|
+
this.mapServiceSignals(this.injector.get(serviceClass));
|
|
84
|
+
},
|
|
85
|
+
onEnter: this.onEnter,
|
|
86
|
+
onExit: this.onExit,
|
|
87
|
+
onSubReturn: this.onSubReturn,
|
|
88
|
+
onSubExit: this.onSubExit,
|
|
89
|
+
onActivate: this.onActivate,
|
|
90
|
+
onDeactivate: this.onDeactivate,
|
|
91
|
+
});
|
|
92
|
+
const completeScopeChange = () => {
|
|
93
|
+
var _a, _b, _c, _d;
|
|
94
|
+
this.scope = this.injector.get(scopeClass);
|
|
95
|
+
this.mapScopeSignals();
|
|
96
|
+
this.updateSignalBindings();
|
|
97
|
+
(_b = (_a = this.scope).onEnter) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
98
|
+
this.onEnter.dispatch(this);
|
|
99
|
+
(_d = (_c = this.scope).onActivate) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
100
|
+
this.onActivate.dispatch(this);
|
|
101
|
+
resolve === null || resolve === void 0 ? void 0 : resolve();
|
|
102
|
+
};
|
|
103
|
+
if (result instanceof Promise) {
|
|
104
|
+
result.then(completeScopeChange);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
completeScopeChange();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
get isRoot() {
|
|
111
|
+
return this === this.stack.rootScope;
|
|
112
|
+
}
|
|
113
|
+
get target() {
|
|
114
|
+
return this.stack.target;
|
|
115
|
+
}
|
|
116
|
+
get isActive() {
|
|
117
|
+
return this === this.stack.activeContext;
|
|
118
|
+
}
|
|
119
|
+
get activeContext() { return this.stack.activeContext; }
|
|
120
|
+
async enterScope(scopeClass, mapping) {
|
|
121
|
+
let newContext;
|
|
122
|
+
const doChange = async () => {
|
|
123
|
+
var _a, _b, _c, _d;
|
|
124
|
+
(_b = (_a = this.activeContext.scope).onSubExit) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
125
|
+
this.activeContext.onSubExit.dispatch(this);
|
|
126
|
+
(_d = (_c = this.activeContext.scope).onDeactivate) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
127
|
+
this.activeContext.onDeactivate.dispatch(this);
|
|
128
|
+
await new Promise(resolve => {
|
|
129
|
+
newContext = new ScopeContext(this.activeContext.injector, scopeClass, mapping, this.activeContext, resolve);
|
|
130
|
+
});
|
|
131
|
+
this.logStack();
|
|
132
|
+
const nextChange = this.stack.queuedScopeChanges.shift();
|
|
133
|
+
if (nextChange) {
|
|
134
|
+
await nextChange();
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
this.stack.ongoingChange = false;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
if (!this.stack.ongoingChange) {
|
|
141
|
+
this.stack.ongoingChange = true;
|
|
142
|
+
await doChange();
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
this.stack.queuedScopeChanges.push(doChange);
|
|
146
|
+
}
|
|
147
|
+
return newContext;
|
|
148
|
+
}
|
|
149
|
+
async exitScope(target) {
|
|
150
|
+
const doChange = async () => {
|
|
151
|
+
if (this.closed)
|
|
152
|
+
throw new Error(`Scope already closed`);
|
|
153
|
+
this.stack.target = target || this.scope.constructor;
|
|
154
|
+
while (true) {
|
|
155
|
+
const ctx = this.stack.stack.pop();
|
|
156
|
+
if (!ctx) {
|
|
157
|
+
throw new Error('no scope in stack');
|
|
158
|
+
}
|
|
159
|
+
ctx.exitThis();
|
|
160
|
+
if (ctx.scope.constructor === this.stack.target) {
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
this.stack.target = undefined;
|
|
165
|
+
const nextChange = this.stack.queuedScopeChanges.shift();
|
|
166
|
+
if (nextChange) {
|
|
167
|
+
await nextChange();
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
this.stack.ongoingChange = false;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
if (!this.stack.ongoingChange) {
|
|
174
|
+
this.stack.ongoingChange = true;
|
|
175
|
+
await doChange();
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
this.stack.queuedScopeChanges.push(doChange);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
closeSubScopes() {
|
|
182
|
+
this.stack.target = this.scope.constructor;
|
|
183
|
+
while (!this.isActive) {
|
|
184
|
+
const ctx = this.stack.stack.pop();
|
|
185
|
+
if (!ctx) {
|
|
186
|
+
throw new Error('no scope in stack');
|
|
187
|
+
}
|
|
188
|
+
ctx.exitThis();
|
|
189
|
+
}
|
|
190
|
+
this.stack.target = undefined;
|
|
191
|
+
}
|
|
192
|
+
logStack() {
|
|
193
|
+
if (exports.SCOPE_CONTEXT.log) {
|
|
194
|
+
console.debug('%c' + this.stack.stack.map(c => c.scope.constructor.name).join(' -> '), 'color:yellow');
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
getStackClasses() {
|
|
198
|
+
return this.stack.stack.map(context => context.scope.constructor);
|
|
199
|
+
}
|
|
200
|
+
addScopeSignal(signal, callback, params) {
|
|
201
|
+
const signalBinding = new ScopeSignalBinding(signal.add(callback, params === null || params === void 0 ? void 0 : params.context), params);
|
|
202
|
+
this.signalBindings.push(signalBinding);
|
|
203
|
+
}
|
|
204
|
+
disableKeepAliveSignals() {
|
|
205
|
+
this.muteKeepAliveSignals = true;
|
|
206
|
+
this.updateSignalBindings();
|
|
207
|
+
}
|
|
208
|
+
enableKeepAliveSignals() {
|
|
209
|
+
this.muteKeepAliveSignals = false;
|
|
210
|
+
this.updateSignalBindings();
|
|
211
|
+
}
|
|
212
|
+
updateSignalBindings(muteKeepAlive = false) {
|
|
213
|
+
var _a;
|
|
214
|
+
for (const binding of this.signalBindings) {
|
|
215
|
+
if (this.isActive) {
|
|
216
|
+
binding.activate();
|
|
217
|
+
}
|
|
218
|
+
else if (muteKeepAlive) {
|
|
219
|
+
binding.deactivate();
|
|
220
|
+
}
|
|
221
|
+
else if (binding.keepAlive === true) {
|
|
222
|
+
binding.activate();
|
|
223
|
+
}
|
|
224
|
+
else if (!!(binding.keepAlive)) {
|
|
225
|
+
if (binding.keepAlive.indexOf(this.activeContext.scope.constructor) != -1) {
|
|
226
|
+
binding.activate();
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
binding.deactivate();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
binding.deactivate();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
muteKeepAlive = muteKeepAlive || this.muteKeepAliveSignals;
|
|
237
|
+
(_a = this.parent) === null || _a === void 0 ? void 0 : _a.updateSignalBindings(muteKeepAlive);
|
|
238
|
+
}
|
|
239
|
+
detachSignalBindings() {
|
|
240
|
+
for (const signalBinding of this.signalBindings) {
|
|
241
|
+
signalBinding.detach();
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
mapScopeSignals() {
|
|
245
|
+
const handlers = exports.scopeSignalHandlers.get(this.scope.constructor);
|
|
246
|
+
if (!handlers)
|
|
247
|
+
return;
|
|
248
|
+
for (const [field, id, options] of handlers) {
|
|
249
|
+
const signal = this.injector.getSignal(id);
|
|
250
|
+
const callback = this.scope[field];
|
|
251
|
+
this.addScopeSignal(signal, callback, Object.assign(Object.assign({}, options), { context: this.scope }));
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
mapServiceSignals(scopeService) {
|
|
255
|
+
const handlers = ecsInjector_1.signalHandlers.get(scopeService.constructor);
|
|
256
|
+
if (!handlers)
|
|
257
|
+
return;
|
|
258
|
+
for (const [field, id] of handlers) {
|
|
259
|
+
const signal = this.injector.getSignal(id);
|
|
260
|
+
const signalBinding = signal.add(scopeService[field], scopeService);
|
|
261
|
+
this.serviceBindings.push(signalBinding);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
detachServiceBindings() {
|
|
265
|
+
for (const binding of this.serviceBindings) {
|
|
266
|
+
binding.detach();
|
|
267
|
+
}
|
|
268
|
+
this.serviceBindings = [];
|
|
269
|
+
}
|
|
270
|
+
exitThis() {
|
|
271
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
272
|
+
if (!this.parent) {
|
|
273
|
+
throw new Error('can\'t exit root scope?!');
|
|
274
|
+
}
|
|
275
|
+
this.logStack();
|
|
276
|
+
this.detachSignalBindings();
|
|
277
|
+
this.detachServiceBindings();
|
|
278
|
+
(_b = (_a = this.scope).onDeactivate) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
279
|
+
this.onDeactivate.dispatch(this);
|
|
280
|
+
(_d = (_c = this.scope).onExit) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
281
|
+
this.onExit.dispatch(this);
|
|
282
|
+
this.injector._dispose();
|
|
283
|
+
this.parent.updateSignalBindings();
|
|
284
|
+
(_f = (_e = this.parent.scope).onSubReturn) === null || _f === void 0 ? void 0 : _f.call(_e);
|
|
285
|
+
this.onSubReturn.dispatch(this);
|
|
286
|
+
(_h = (_g = this.parent.scope).onActivate) === null || _h === void 0 ? void 0 : _h.call(_g);
|
|
287
|
+
this.parent.onActivate.dispatch(this);
|
|
288
|
+
this.closed = true;
|
|
289
|
+
this.onEnter.detachAll();
|
|
290
|
+
this.onExit.detachAll();
|
|
291
|
+
this.onSubReturn.detachAll();
|
|
292
|
+
this.onSubExit.detachAll();
|
|
293
|
+
this.onActivate.detachAll();
|
|
294
|
+
this.onDeactivate.detachAll();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
exports.ScopeContext = ScopeContext;
|
|
207
298
|
//# sourceMappingURL=scopeContext.js.map
|