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ateDeclaration } from './interface';\nimport { StateObject } from './stateObject';\nimport { StateBuilder } from './stateBuilder';\nimport { StateRegistryListener } from './stateRegistry';\nimport { Disposable } from '../interface';\nimport { UIRouter } from '../router';\n\nexport class StateQueueManager implements Disposable {\n queue: StateObject[] = [];\n\n constructor(\n private router: UIRouter,\n public states: { [key: string]: StateObject },\n public builder: StateBuilder,\n public listeners: StateRegistryListener[]\n ) {}\n\n dispose() {\n this.queue = [];\n }\n\n register(stateDecl: _StateDeclaration) {\n const queue = this.queue;\n const state = StateObject.create(stateDecl);\n const name = state.name;\n\n if (!isString(name)) throw new Error('State must have a valid name');\n if (this.states.hasOwnProperty(name) || inArray(queue.map(prop('name')), name))\n throw new Error(`State '${name}' is already defined`);\n\n queue.push(state);\n this.flush();\n\n return state;\n }\n\n flush() {\n const { queue, states, builder } = this;\n const registered: StateObject[] = [], // states that got registered\n orphans: StateObject[] = [], // states that don't yet have a parent registered\n previousQueueLength = {}; // keep track of how long the queue when an orphan was first encountered\n const getState = (name) => this.states.hasOwnProperty(name) && this.states[name];\n const notifyListeners = () => {\n if (registered.length) {\n this.listeners.forEach((listener) =>\n listener(\n 'registered',\n registered.map((s) => s.self)\n )\n );\n }\n };\n\n while (queue.length > 0) {\n const state: StateObject = queue.shift();\n const name = state.name;\n const result: StateObject = builder.build(state);\n const orphanIdx: number = orphans.indexOf(state);\n\n if (result) {\n const existingState = getState(name);\n if (existingState && existingState.name === name) {\n throw new Error(`State '${name}' is already defined`);\n }\n\n const existingFutureState = getState(name + '.**');\n if (existingFutureState) {\n // Remove future state of the same name\n this.router.stateRegistry.deregister(existingFutureState);\n }\n\n states[name] = state;\n this.attachRoute(state);\n if (orphanIdx >= 0) orphans.splice(orphanIdx, 1);\n registered.push(state);\n continue;\n }\n\n const prev = previousQueueLength[name];\n previousQueueLength[name] = queue.length;\n if (orphanIdx >= 0 && prev === queue.length) {\n // Wait until two consecutive iterations where no additional states were dequeued successfully.\n // throw new Error(`Cannot register orphaned state '${name}'`);\n queue.push(state);\n notifyListeners();\n return states;\n } else if (orphanIdx < 0) {\n orphans.push(state);\n }\n\n queue.push(state);\n }\n\n notifyListeners();\n return states;\n }\n\n attachRoute(state: StateObject) {\n if (state.abstract || !state.url) return;\n const rulesApi = this.router.urlService.rules;\n rulesApi.rule(rulesApi.urlRuleFactory.create(state));\n }\n}\n"
12 ]
13}
\No newline at end of file