UNPKG

11.2 kBTypeScriptView Raw
1declare module '@ember/application/instance' {
2 /**
3 @module @ember/application
4 */
5 import EngineInstance from '@ember/engine/instance';
6 import type { BootOptions } from '@ember/engine/instance';
7 import type Application from '@ember/application';
8 import type { BootEnvironment } from '@ember/-internals/glimmer';
9 import Router from '@ember/routing/router';
10 import type { ViewMixin } from '@ember/-internals/views';
11 import { EventDispatcher } from '@ember/-internals/views';
12 import type { Registry } from '@ember/-internals/container';
13 import type { SimpleElement } from '@simple-dom/interface';
14 /**
15 The `ApplicationInstance` encapsulates all of the stateful aspects of a
16 running `Application`.
17
18 At a high-level, we break application boot into two distinct phases:
19
20 * Definition time, where all of the classes, templates, and other
21 dependencies are loaded (typically in the browser).
22 * Run time, where we begin executing the application once everything
23 has loaded.
24
25 Definition time can be expensive and only needs to happen once since it is
26 an idempotent operation. For example, between test runs and FastBoot
27 requests, the application stays the same. It is only the state that we want
28 to reset.
29
30 That state is what the `ApplicationInstance` manages: it is responsible for
31 creating the container that contains all application state, and disposing of
32 it once the particular test run or FastBoot request has finished.
33
34 @public
35 @class ApplicationInstance
36 @extends EngineInstance
37 */
38 class ApplicationInstance extends EngineInstance {
39 /**
40 The `Application` for which this is an instance.
41
42 @property {Application} application
43 @private
44 */
45 application: Application;
46 /**
47 The root DOM element of the Application as an element or a
48 CSS selector.
49
50 @private
51 @property {String|DOMElement} rootElement
52 */
53 rootElement: string | Element | SimpleElement | null;
54 customEvents: Record<string, string | null> | null;
55 init(properties: object | undefined): void;
56 /**
57 Overrides the base `EngineInstance._bootSync` method with concerns relevant
58 to booting application (instead of engine) instances.
59
60 This method should only contain synchronous boot concerns. Asynchronous
61 boot concerns should eventually be moved to the `boot` method, which
62 returns a promise.
63
64 Until all boot code has been made asynchronous, we need to continue to
65 expose this method for use *internally* in places where we need to boot an
66 instance synchronously.
67
68 @private
69 */
70 _bootSync(options?: BootOptions): this;
71 setupRegistry(options: BootOptions): void;
72 _router?: Router;
73 get router(): Router;
74 /**
75 This hook is called by the root-most Route (a.k.a. the ApplicationRoute)
76 when it has finished creating the root View. By default, we simply take the
77 view and append it to the `rootElement` specified on the Application.
78
79 In cases like FastBoot and testing, we can override this hook and implement
80 custom behavior, such as serializing to a string and sending over an HTTP
81 socket rather than appending to DOM.
82
83 @param view {Ember.View} the root-most view
84 @deprecated
85 @private
86 */
87 didCreateRootView(view: ViewMixin): void;
88 /**
89 Tells the router to start routing. The router will ask the location for the
90 current URL of the page to determine the initial URL to start routing to.
91 To start the app at a specific URL, call `handleURL` instead.
92
93 @private
94 */
95 startRouting(): void;
96 /**
97 Sets up the router, initializing the child router and configuring the
98 location before routing begins.
99
100 Because setup should only occur once, multiple calls to `setupRouter`
101 beyond the first call have no effect.
102
103 This is commonly used in order to confirm things that rely on the router
104 are functioning properly from tests that are primarily rendering related.
105
106 For example, from within [ember-qunit](https://github.com/emberjs/ember-qunit)'s
107 `setupRenderingTest` calling `this.owner.setupRouter()` would allow that
108 rendering test to confirm that any `<LinkTo></LinkTo>`'s that are rendered
109 have the correct URL.
110
111 @public
112 */
113 setupRouter(): void;
114 /**
115 Directs the router to route to a particular URL. This is useful in tests,
116 for example, to tell the app to start at a particular URL.
117
118 @param url {String} the URL the router should route to
119 @private
120 */
121 handleURL(
122 url: string
123 ): import('router_js').InternalTransition<import('@ember/routing/route').default<unknown>>;
124 /**
125 @private
126 */
127 setupEventDispatcher(): EventDispatcher;
128 /**
129 Returns the current URL of the app instance. This is useful when your
130 app does not update the browsers URL bar (i.e. it uses the `'none'`
131 location adapter).
132
133 @public
134 @return {String} the current URL
135 */
136 getURL(): string;
137 /**
138 Navigate the instance to a particular URL. This is useful in tests, for
139 example, or to tell the app to start at a particular URL. This method
140 returns a promise that resolves with the app instance when the transition
141 is complete, or rejects if the transition was aborted due to an error.
142
143 @public
144 @param url {String} the destination URL
145 @return {Promise<ApplicationInstance>}
146 */
147 visit(url: string): import('rsvp').Promise<unknown>;
148 willDestroy(): void;
149 /**
150 @private
151 @method setupRegistry
152 @param {Registry} registry
153 @param {BootOptions} options
154 */
155 static setupRegistry(registry: Registry, options?: BootOptions | _BootOptions): void;
156 }
157 /**
158 A list of boot-time configuration options for customizing the behavior of
159 an `ApplicationInstance`.
160
161 This is an interface class that exists purely to document the available
162 options; you do not need to construct it manually. Simply pass a regular
163 JavaScript object containing the desired options into methods that require
164 one of these options object:
165
166 ```javascript
167 MyApp.visit("/", { location: "none", rootElement: "#container" });
168 ```
169
170 Not all combinations of the supported options are valid. See the documentation
171 on `Application#visit` for the supported configurations.
172
173 Internal, experimental or otherwise unstable flags are marked as private.
174
175 @class BootOptions
176 @namespace ApplicationInstance
177 @public
178 */
179 class _BootOptions {
180 /**
181 Interactive mode: whether we need to set up event delegation and invoke
182 lifecycle callbacks on Components.
183
184 @property isInteractive
185 @type boolean
186 @default auto-detected
187 @private
188 */
189 readonly isInteractive: boolean;
190 /**
191 @property _renderMode
192 @type string
193 @default undefined
194 @private
195 */
196 readonly _renderMode?: string;
197 /**
198 Run in a full browser environment.
199
200 When this flag is set to `false`, it will disable most browser-specific
201 and interactive features. Specifically:
202
203 * It does not use `jQuery` to append the root view; the `rootElement`
204 (either specified as a subsequent option or on the application itself)
205 must already be an `Element` in the given `document` (as opposed to a
206 string selector).
207
208 * It does not set up an `EventDispatcher`.
209
210 * It does not run any `Component` lifecycle hooks (such as `didInsertElement`).
211
212 * It sets the `location` option to `"none"`. (If you would like to use
213 the location adapter specified in the app's router instead, you can also
214 specify `{ location: null }` to specifically opt-out.)
215
216 @property isBrowser
217 @type boolean
218 @default auto-detected
219 @public
220 */
221 readonly isBrowser: boolean;
222 /**
223 If present, overrides the router's `location` property with this
224 value. This is useful for environments where trying to modify the
225 URL would be inappropriate.
226
227 @property location
228 @type string
229 @default null
230 @public
231 */
232 readonly location: string | null;
233 /**
234 Disable rendering completely.
235
236 When this flag is set to `false`, it will disable the entire rendering
237 pipeline. Essentially, this puts the app into "routing-only" mode. No
238 templates will be rendered, and no Components will be created.
239
240 @property shouldRender
241 @type boolean
242 @default true
243 @public
244 */
245 readonly shouldRender: boolean;
246 /**
247 If present, render into the given `Document` object instead of the
248 global `window.document` object.
249
250 In practice, this is only useful in non-browser environment or in
251 non-interactive mode, because Ember's `jQuery` dependency is
252 implicitly bound to the current document, causing event delegation
253 to not work properly when the app is rendered into a foreign
254 document object (such as an iframe's `contentDocument`).
255
256 In non-browser mode, this could be a "`Document`-like" object as
257 Ember only interact with a small subset of the DOM API in non-
258 interactive mode. While the exact requirements have not yet been
259 formalized, the `SimpleDOM` library's implementation is known to
260 work.
261
262 @property document
263 @type Document
264 @default the global `document` object
265 @public
266 */
267 readonly document: Document | null;
268 /**
269 If present, overrides the application's `rootElement` property on
270 the instance. This is useful for testing environment, where you
271 might want to append the root view to a fixture area.
272
273 In non-browser mode, because Ember does not have access to jQuery,
274 this options must be specified as a DOM `Element` object instead of
275 a selector string.
276
277 See the documentation on `Application`'s `rootElement` for
278 details.
279
280 @property rootElement
281 @type String|Element
282 @default null
283 @public
284 */
285 readonly rootElement?: string | SimpleElement;
286 constructor(options?: BootOptions);
287 toEnvironment(): BootEnvironment;
288 }
289 export default ApplicationInstance;
290}