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K,OAAA,CAAC,CAAC,IAAI,EAAN,CAAM,CAAC,CACtC;QAHD,CAGC,CACF,CAAC;QACF,OAAO,kBAAkB,CAAC;IAC5B,CAAC;IAuBD,2BAAG,GAAH,UAAI,WAAyB,EAAE,IAAkB;QAAjD,iBAKC;QAJC,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;YACxB,OAA2B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,UAAC,IAAI,IAAK,OAAA,KAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAtB,CAAsB,CAAC,CAAC;QAC5F,IAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;QACnD,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;IACvC,CAAC;IAED;;;;;;;;;OASG;IACH,iCAAS,GAAT,UAAU,QAAgB,EAAE,eAAgC;QAC1D,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;IACzD,CAAC;IACH,oBAAC;AAAD,CAAC,AAzMD,IAyMC;AAzMY,sCAAa",
10 "sourcesContent": [
11 "import { StateObject } from './stateObject';\nimport { StateMatcher } from './stateMatcher';\nimport { StateBuilder } from './stateBuilder';\nimport { StateQueueManager } from './stateQueueManager';\nimport { StateDeclaration, _StateDeclaration } from './interface';\nimport { BuilderFunction } from './stateBuilder';\nimport { StateOrName } from './interface';\nimport { removeFrom } from '../common/common';\nimport { UIRouter } from '../router';\nimport { propEq } from '../common/hof';\n\n/**\n * The signature for the callback function provided to [[StateRegistry.onStatesChanged]].\n *\n * This callback receives two parameters:\n *\n * @param event a string; either \"registered\" or \"deregistered\"\n * @param states the list of [[StateDeclaration]]s that were registered (or deregistered).\n */\nexport type StateRegistryListener = (event: 'registered' | 'deregistered', states: StateDeclaration[]) => void;\n\n/**\n * A registry for all of the application's [[StateDeclaration]]s\n *\n * This API is found at `router.stateRegistry` ([[UIRouter.stateRegistry]])\n */\nexport class StateRegistry {\n private _root: StateObject;\n private states: { [key: string]: StateObject } = {};\n\n /** @internal */\n matcher: StateMatcher;\n private builder: StateBuilder;\n /** @internal */\n stateQueue: StateQueueManager;\n\n /** @internal */\n listeners: StateRegistryListener[] = [];\n\n /** @internal */\n constructor(private router: UIRouter) {\n this.matcher = new StateMatcher(this.states);\n this.builder = new StateBuilder(this.matcher, router.urlMatcherFactory);\n this.stateQueue = new StateQueueManager(router, this.states, this.builder, this.listeners);\n this._registerRoot();\n }\n\n /** @internal */\n private _registerRoot() {\n const rootStateDef: StateDeclaration = {\n name: '',\n url: '^',\n views: null,\n params: {\n '#': { value: null, type: 'hash', dynamic: true },\n },\n abstract: true,\n };\n\n const _root = (this._root = this.stateQueue.register(rootStateDef));\n _root.navigable = null;\n }\n\n /** @internal */\n dispose() {\n this.stateQueue.dispose();\n this.listeners = [];\n this.get().forEach((state) => this.get(state) && this.deregister(state));\n }\n\n /**\n * Listen for a State Registry events\n *\n * Adds a callback that is invoked when states are registered or deregistered with the StateRegistry.\n *\n * #### Example:\n * ```js\n * let allStates = registry.get();\n *\n * // Later, invoke deregisterFn() to remove the listener\n * let deregisterFn = registry.onStatesChanged((event, states) => {\n * switch(event) {\n * case: 'registered':\n * states.forEach(state => allStates.push(state));\n * break;\n * case: 'deregistered':\n * states.forEach(state => {\n * let idx = allStates.indexOf(state);\n * if (idx !== -1) allStates.splice(idx, 1);\n * });\n * break;\n * }\n * });\n * ```\n *\n * @param listener a callback function invoked when the registered states changes.\n * The function receives two parameters, `event` and `state`.\n * See [[StateRegistryListener]]\n * @return a function that deregisters the listener\n */\n onStatesChanged(listener: StateRegistryListener): () => void {\n this.listeners.push(listener);\n return function deregisterListener() {\n removeFrom(this.listeners)(listener);\n }.bind(this);\n }\n\n /**\n * Gets the implicit root state\n *\n * Gets the root of the state tree.\n * The root state is implicitly created by UI-Router.\n * Note: this returns the internal [[StateObject]] representation, not a [[StateDeclaration]]\n *\n * @return the root [[StateObject]]\n */\n root() {\n return this._root;\n }\n\n /**\n * Adds a state to the registry\n *\n * Registers a [[StateDeclaration]] or queues it for registration.\n *\n * Note: a state will be queued if the state's parent isn't yet registered.\n *\n * @param stateDefinition the definition of the state to register.\n * @returns the internal [[StateObject]] object.\n * If the state was successfully registered, then the object is fully built (See: [[StateBuilder]]).\n * If the state was only queued, then the object is not fully built.\n */\n register(stateDefinition: _StateDeclaration): StateObject {\n return this.stateQueue.register(stateDefinition);\n }\n\n /** @internal */\n private _deregisterTree(state: StateObject) {\n const all = this.get().map((s) => s.$$state());\n const getChildren = (states: StateObject[]) => {\n const _children = all.filter((s) => states.indexOf(s.parent) !== -1);\n return _children.length === 0 ? _children : _children.concat(getChildren(_children));\n };\n\n const children = getChildren([state]);\n const deregistered: StateObject[] = [state].concat(children).reverse();\n\n deregistered.forEach((_state) => {\n const rulesApi = this.router.urlService.rules;\n\n // Remove URL rule\n rulesApi\n .rules()\n .filter(propEq('state', _state))\n .forEach((rule) => rulesApi.removeRule(rule));\n\n // Remove state from registry\n delete this.states[_state.name];\n });\n\n return deregistered;\n }\n\n /**\n * Removes a state from the registry\n *\n * This removes a state from the registry.\n * If the state has children, they are are also removed from the registry.\n *\n * @param stateOrName the state's name or object representation\n * @returns {StateObject[]} a list of removed states\n */\n deregister(stateOrName: StateOrName) {\n const _state = this.get(stateOrName);\n if (!_state) throw new Error(\"Can't deregister state; not found: \" + stateOrName);\n const deregisteredStates = this._deregisterTree(_state.$$state());\n\n this.listeners.forEach((listener) =>\n listener(\n 'deregistered',\n deregisteredStates.map((s) => s.self)\n )\n );\n return deregisteredStates;\n }\n\n /**\n * Gets all registered states\n *\n * Calling this method with no arguments will return a list of all the states that are currently registered.\n * Note: this does not return states that are *queued* but not yet registered.\n *\n * @return a list of [[StateDeclaration]]s\n */\n get(): StateDeclaration[];\n\n /**\n * Gets a registered state\n *\n * Given a state or a name, finds and returns the [[StateDeclaration]] from the registry.\n * Note: this does not return states that are *queued* but not yet registered.\n *\n * @param stateOrName either the name of a state, or a state object.\n * @param base the base state to use when stateOrName is relative.\n * @return a registered [[StateDeclaration]] that matched the `stateOrName`, or null if the state isn't registered.\n */\n get(stateOrName: StateOrName, base?: StateOrName): StateDeclaration;\n get(stateOrName?: StateOrName, base?: StateOrName): any {\n if (arguments.length === 0)\n return <StateDeclaration[]>Object.keys(this.states).map((name) => this.states[name].self);\n const found = this.matcher.find(stateOrName, base);\n return (found && found.self) || null;\n }\n\n /**\n * Registers a [[BuilderFunction]] for a specific [[StateObject]] property (e.g., `parent`, `url`, or `path`).\n * More than one BuilderFunction can be registered for a given property.\n *\n * The BuilderFunction(s) will be used to define the property on any subsequently built [[StateObject]] objects.\n *\n * @param property The name of the State property being registered for.\n * @param builderFunction The BuilderFunction which will be used to build the State property\n * @returns a function which deregisters the BuilderFunction\n */\n decorator(property: string, builderFunction: BuilderFunction) {\n return this.builder.builder(property, builderFunction);\n }\n}\n"
12 ]
13}
\No newline at end of file