From 5a9bac9bdb384b6db52ff07d5ae51b84ac7aa0d4 Mon Sep 17 00:00:00 2001 From: Chris Thielen Date: Sat, 28 Apr 2018 16:08:37 -0700 Subject: [PATCH] fix(StateRegistry): Notify listeners of added states when there are orphans in the state queue Closes https://github.com/ui-router/core/issues/170 --- src/state/stateQueueManager.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/state/stateQueueManager.ts b/src/state/stateQueueManager.ts index d1c0ebd9..59ea128e 100644 --- a/src/state/stateQueueManager.ts +++ b/src/state/stateQueueManager.ts @@ -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(); @@ -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); @@ -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; }