Skip to content

Commit

Permalink
fix(StateRegistry): Notify listeners of added states when there are o…
Browse files Browse the repository at this point in the history
…rphans in the state queue

Closes #170
  • Loading branch information
christopherthielen committed Apr 28, 2018
1 parent ebea30e commit 5a9bac9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/state/stateQueueManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ export class StateQueueManager implements Disposable {
orphans: StateObject[] = [], // states that don't yet have a parent registered
previousQueueLength = {}; // keep track of how long the queue when an orphan was first encountered
const getState = name => this.states.hasOwnProperty(name) && this.states[name];
const notifyListeners = () => {
if (registered.length) {
this.listeners.forEach(listener => listener('registered', registered.map(s => s.self)));
}
};

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

if (registered.length) {
this.listeners.forEach(listener => listener('registered', registered.map(s => s.self)));
}

notifyListeners();
return states;
}

Expand Down

0 comments on commit 5a9bac9

Please sign in to comment.