1 | import { StateObject } from './stateObject';
|
2 | import { StateMatcher } from './stateMatcher';
|
3 | import { UrlMatcherFactory } from '../url/urlMatcherFactory';
|
4 | import { Resolvable } from '../resolve/resolvable';
|
5 | /**
|
6 | * A function that builds the final value for a specific field on a [[StateObject]].
|
7 | *
|
8 | * A series of builder functions for a given field are chained together.
|
9 | * The final value returned from the chain of builders is applied to the built [[StateObject]].
|
10 | * Builder functions should call the [[parent]] function either first or last depending on the desired composition behavior.
|
11 | *
|
12 | * @param state the _partially built_ [[StateObject]]. The [[StateDeclaration]] can be inspected via [[StateObject.self]]
|
13 | * @param parent the previous builder function in the series.
|
14 | */
|
15 | export type BuilderFunction = (state: StateObject, parent?: BuilderFunction) => any;
|
16 | /**
|
17 | * This is a [[StateBuilder.builder]] function for the `resolve:` block on a [[StateDeclaration]].
|
18 | *
|
19 | * When the [[StateBuilder]] builds a [[StateObject]] object from a raw [[StateDeclaration]], this builder
|
20 | * validates the `resolve` property and converts it to a [[Resolvable]] array.
|
21 | *
|
22 | * resolve: input value can be:
|
23 | *
|
24 | * {
|
25 | * // analyzed but not injected
|
26 | * myFooResolve: function() { return "myFooData"; },
|
27 | *
|
28 | * // function.toString() parsed, "DependencyName" dep as string (not min-safe)
|
29 | * myBarResolve: function(DependencyName) { return DependencyName.fetchSomethingAsPromise() },
|
30 | *
|
31 | * // Array split; "DependencyName" dep as string
|
32 | * myBazResolve: [ "DependencyName", function(dep) { return dep.fetchSomethingAsPromise() },
|
33 | *
|
34 | * // Array split; DependencyType dep as token (compared using ===)
|
35 | * myQuxResolve: [ DependencyType, function(dep) { return dep.fetchSometingAsPromise() },
|
36 | *
|
37 | * // val.$inject used as deps
|
38 | * // where:
|
39 | * // corgeResolve.$inject = ["DependencyName"];
|
40 | * // function corgeResolve(dep) { dep.fetchSometingAsPromise() }
|
41 | * // then "DependencyName" dep as string
|
42 | * myCorgeResolve: corgeResolve,
|
43 | *
|
44 | * // inject service by name
|
45 | * // When a string is found, desugar creating a resolve that injects the named service
|
46 | * myGraultResolve: "SomeService"
|
47 | * }
|
48 | *
|
49 | * or:
|
50 | *
|
51 | * [
|
52 | * new Resolvable("myFooResolve", function() { return "myFooData" }),
|
53 | * new Resolvable("myBarResolve", function(dep) { return dep.fetchSomethingAsPromise() }, [ "DependencyName" ]),
|
54 | * { provide: "myBazResolve", useFactory: function(dep) { dep.fetchSomethingAsPromise() }, deps: [ "DependencyName" ] }
|
55 | * ]
|
56 | */
|
57 | export declare function resolvablesBuilder(state: StateObject): Resolvable[];
|
58 | /**
|
59 | * A internal global service
|
60 | *
|
61 | * StateBuilder is a factory for the internal [[StateObject]] objects.
|
62 | *
|
63 | * When you register a state with the [[StateRegistry]], you register a plain old javascript object which
|
64 | * conforms to the [[StateDeclaration]] interface. This factory takes that object and builds the corresponding
|
65 | * [[StateObject]] object, which has an API and is used internally.
|
66 | *
|
67 | * Custom properties or API may be added to the internal [[StateObject]] object by registering a decorator function
|
68 | * using the [[builder]] method.
|
69 | */
|
70 | export declare class StateBuilder {
|
71 | private matcher;
|
72 | /** An object that contains all the BuilderFunctions registered, key'd by the name of the State property they build */
|
73 | private builders;
|
74 | constructor(matcher: StateMatcher, urlMatcherFactory: UrlMatcherFactory);
|
75 | /**
|
76 | * Registers a [[BuilderFunction]] for a specific [[StateObject]] property (e.g., `parent`, `url`, or `path`).
|
77 | * More than one BuilderFunction can be registered for a given property.
|
78 | *
|
79 | * The BuilderFunction(s) will be used to define the property on any subsequently built [[StateObject]] objects.
|
80 | *
|
81 | * @param property The name of the State property being registered for.
|
82 | * @param fn The BuilderFunction which will be used to build the State property
|
83 | * @returns a function which deregisters the BuilderFunction
|
84 | */
|
85 | builder(property: string, fn: BuilderFunction): Function;
|
86 | /**
|
87 | * Gets the registered builder functions for a given property of [[StateObject]].
|
88 | *
|
89 | * @param property The name of the State property being registered for.
|
90 | * @returns the registered builder(s).
|
91 | * note: for backwards compatibility, this may be a single builder or an array of builders
|
92 | */
|
93 | builder(property: string): BuilderFunction | BuilderFunction[];
|
94 | /**
|
95 | * Builds all of the properties on an essentially blank State object, returning a State object which has all its
|
96 | * properties and API built.
|
97 | *
|
98 | * @param state an uninitialized State object
|
99 | * @returns the built State object
|
100 | */
|
101 | build(state: StateObject): StateObject;
|
102 | parentName(state: StateObject): string;
|
103 | name(state: StateObject): string;
|
104 | }
|