Skip to content

Commit 8f3d1c3

Browse files
committed
Child is just an instance instead of nested object
1 parent 07acf6f commit 8f3d1c3

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

src/index.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ class InternalInstance {
154154
private parent: null | InternalInstance
155155
private globalHandlers = new Handlers()
156156
private resolved = null as Promise<Array<any>> | null
157-
// TODO: Just can have reference to child instance, and use childInstance.definition
158-
child: null | { definition: () => Generator<Yielded, StateDefinition, never>, instance: InternalInstance } = null
157+
child: null | InternalInstance = null
159158

160159
constructor(
161160
parent: null | InternalInstance,
@@ -175,7 +174,7 @@ class InternalInstance {
175174
if (this.child === null) {
176175
return this.definition.name;
177176
} else {
178-
return { [this.definition.name]: this.child.instance.current };
177+
return { [this.definition.name]: this.child.current };
179178
}
180179
// if (this.child === null) {
181180
// return null;
@@ -187,7 +186,7 @@ class InternalInstance {
187186
private *generateActions(): Generator<EntryAction, void, undefined> {
188187
yield* this.globalHandlers.actions();
189188
if (this.child !== null) {
190-
yield* this.child.instance.generateActions();
189+
yield* this.child.generateActions();
191190
}
192191
}
193192

@@ -200,7 +199,7 @@ class InternalInstance {
200199
yield* await this.resolved;
201200
}
202201
if (this.child !== null) {
203-
yield* this.child.instance.valuePromises();
202+
yield* this.child.valuePromises();
204203
}
205204
}
206205

@@ -277,15 +276,15 @@ class InternalInstance {
277276
return;
278277
}
279278

280-
this.child.instance.willExit();
279+
this.child.willExit();
281280
}
282281

283282
this.willExit();
284283

285284
// this.resolved = null;
286285

287286
const childInstance = new InternalInstance(this, stateDefinition, this.callbacks);
288-
this.child = { definition: stateDefinition, instance: childInstance };
287+
this.child = childInstance;
289288
childInstance.didEnter();
290289
}
291290

@@ -307,7 +306,7 @@ class InternalInstance {
307306
for (const nestedTarget of target.targets) {
308307
receiver.transitionTo(nestedTarget);
309308
if (receiver.child !== null) {
310-
receiver = receiver.child.instance;
309+
receiver = receiver.child;
311310
} else {
312311
break;
313312
}
@@ -326,7 +325,7 @@ class InternalInstance {
326325
}
327326

328327
receive(event: string) {
329-
this.child?.instance.receive(event);
328+
this.child?.receive(event);
330329

331330
const target = this.globalHandlers.targetForEvent(event);
332331
if (target !== undefined) {

0 commit comments

Comments
 (0)