Skip to content

Commit 5a9bac9

Browse files
committedApr 28, 2018
fix(StateRegistry): Notify listeners of added states when there are orphans in the state queue
Closes #170
1 parent ebea30e commit 5a9bac9

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed
 

‎src/state/stateQueueManager.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ export class StateQueueManager implements Disposable {
5252
orphans: StateObject[] = [], // states that don't yet have a parent registered
5353
previousQueueLength = {}; // keep track of how long the queue when an orphan was first encountered
5454
const getState = name => this.states.hasOwnProperty(name) && this.states[name];
55+
const notifyListeners = () => {
56+
if (registered.length) {
57+
this.listeners.forEach(listener => listener('registered', registered.map(s => s.self)));
58+
}
59+
};
5560

5661
while (queue.length > 0) {
5762
const state: StateObject = queue.shift();
@@ -84,6 +89,7 @@ export class StateQueueManager implements Disposable {
8489
// Wait until two consecutive iterations where no additional states were dequeued successfully.
8590
// throw new Error(`Cannot register orphaned state '${name}'`);
8691
queue.push(state);
92+
notifyListeners();
8793
return states;
8894
} else if (orphanIdx < 0) {
8995
orphans.push(state);
@@ -92,10 +98,7 @@ export class StateQueueManager implements Disposable {
9298
queue.push(state);
9399
}
94100

95-
if (registered.length) {
96-
this.listeners.forEach(listener => listener('registered', registered.map(s => s.self)));
97-
}
98-
101+
notifyListeners();
99102
return states;
100103
}
101104

0 commit comments

Comments
 (0)
Please sign in to comment.