ember-source 4.8.0-alpha.5 → 4.8.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/CHANGELOG.md +11 -2
  2. package/blueprints/helper/files/__root__/{__collection__ → helpers}/__name__.ts +0 -0
  3. package/blueprints/helper/index.js +0 -15
  4. package/blueprints/helper-test/index.js +0 -3
  5. package/blueprints/helper-test/mocha-0.12-files/__root__/__testType__/{__collection__ → helpers}/__name__-test.js +0 -0
  6. package/blueprints/helper-test/mocha-files/__root__/__testType__/{__collection__ → helpers}/__name__-test.js +0 -0
  7. package/blueprints/helper-test/mocha-rfc-232-files/__root__/__testType__/{__collection__ → helpers}/__name__-test.ts +0 -0
  8. package/blueprints/helper-test/qunit-files/__root__/__testType__/{__collection__ → helpers}/__name__-test.js +0 -0
  9. package/blueprints/helper-test/qunit-rfc-232-files/__root__/__testType__/{__collection__ → helpers}/__name__-test.ts +0 -0
  10. package/blueprints-js/helper/files/__root__/{__collection__ → helpers}/__name__.js +0 -0
  11. package/blueprints-js/helper-test/mocha-0.12-files/__root__/__testType__/{__collection__ → helpers}/__name__-test.js +0 -0
  12. package/blueprints-js/helper-test/mocha-files/__root__/__testType__/{__collection__ → helpers}/__name__-test.js +0 -0
  13. package/blueprints-js/helper-test/mocha-rfc-232-files/__root__/__testType__/{__collection__ → helpers}/__name__-test.js +0 -0
  14. package/blueprints-js/helper-test/qunit-files/__root__/__testType__/{__collection__ → helpers}/__name__-test.js +0 -0
  15. package/blueprints-js/helper-test/qunit-rfc-232-files/__root__/__testType__/{__collection__ → helpers}/__name__-test.js +0 -0
  16. package/build-metadata.json +3 -3
  17. package/dist/dependencies/router_js.js +1 -1
  18. package/dist/ember-template-compiler.js +675 -18
  19. package/dist/ember-template-compiler.map +1 -1
  20. package/dist/ember-testing.js +11 -11
  21. package/dist/ember-testing.map +1 -1
  22. package/dist/ember.debug.js +19576 -20510
  23. package/dist/ember.debug.map +1 -1
  24. package/dist/header/license.js +1 -1
  25. package/dist/packages/@ember/-internals/glimmer/index.js +4 -2
  26. package/dist/packages/@ember/-internals/metal/index.js +214 -1094
  27. package/dist/packages/@ember/-internals/routing/index.js +1 -17
  28. package/dist/packages/@ember/-internals/runtime/index.js +3 -16
  29. package/dist/packages/@ember/-internals/runtime/lib/mixins/-proxy.js +2 -1
  30. package/dist/packages/@ember/-internals/runtime/lib/mixins/action_handler.js +4 -3
  31. package/dist/packages/@ember/-internals/runtime/lib/mixins/comparable.js +1 -1
  32. package/dist/packages/@ember/-internals/runtime/lib/mixins/container_proxy.js +1 -1
  33. package/dist/packages/@ember/-internals/runtime/lib/mixins/registry_proxy.js +1 -8
  34. package/dist/packages/@ember/-internals/runtime/lib/mixins/target_action_support.js +2 -1
  35. package/dist/packages/@ember/-internals/utils/index.js +3 -3
  36. package/dist/packages/@ember/-internals/views/lib/component_lookup.js +1 -1
  37. package/dist/packages/@ember/-internals/views/lib/mixins/action_support.js +2 -1
  38. package/dist/packages/@ember/-internals/views/lib/mixins/child_views_support.js +2 -1
  39. package/dist/packages/@ember/-internals/views/lib/mixins/class_names_support.js +2 -1
  40. package/dist/packages/@ember/-internals/views/lib/mixins/view_state_support.js +1 -1
  41. package/dist/packages/@ember/-internals/views/lib/mixins/view_support.js +2 -1
  42. package/dist/packages/@ember/-internals/views/lib/system/event_dispatcher.js +1 -1
  43. package/dist/packages/@ember/-internals/views/lib/views/core_view.js +3 -1
  44. package/dist/packages/@ember/application/index.js +876 -2
  45. package/dist/packages/@ember/application/instance.js +2 -2
  46. package/dist/packages/@ember/application/namespace.js +70 -1
  47. package/dist/packages/@ember/array/index.js +1503 -2
  48. package/dist/packages/@ember/array/mutable.js +1 -1
  49. package/dist/packages/@ember/array/proxy.js +307 -1
  50. package/dist/packages/@ember/canary-features/index.js +2 -2
  51. package/dist/packages/@ember/controller/index.js +260 -3
  52. package/dist/packages/@ember/debug/container-debug-adapter.js +99 -1
  53. package/dist/packages/@ember/debug/data-adapter.js +574 -1
  54. package/dist/packages/@ember/engine/index.js +5 -5
  55. package/dist/packages/@ember/engine/instance.js +4 -4
  56. package/dist/packages/@ember/enumerable/index.js +3 -1
  57. package/dist/packages/@ember/enumerable/mutable.js +4 -0
  58. package/dist/packages/@ember/{-internals/runtime/lib/system/object.js → object/-internals.js} +4 -17
  59. package/dist/packages/@ember/object/core.js +731 -1
  60. package/dist/packages/@ember/object/evented.js +93 -2
  61. package/dist/packages/@ember/object/index.js +76 -4
  62. package/dist/packages/@ember/object/internals.js +3 -2
  63. package/dist/packages/@ember/object/lib/computed/computed_macros.js +3 -1
  64. package/dist/packages/@ember/object/lib/computed/reduce_computed_macros.js +4 -3
  65. package/dist/packages/@ember/object/mixin.js +659 -1
  66. package/dist/packages/@ember/object/observable.js +341 -1
  67. package/dist/packages/@ember/object/promise-proxy-mixin.js +150 -1
  68. package/dist/packages/@ember/object/proxy.js +10 -1
  69. package/dist/packages/@ember/routing/-internals.js +7 -0
  70. package/dist/packages/@ember/routing/auto-location.js +249 -1
  71. package/dist/packages/@ember/routing/hash-location.js +169 -1
  72. package/dist/packages/@ember/routing/history-location.js +289 -1
  73. package/dist/packages/@ember/{-internals/routing/lib/system → routing/lib}/cache.js +0 -0
  74. package/dist/packages/@ember/{-internals/routing/lib/system → routing/lib}/controller_for.js +0 -0
  75. package/dist/packages/@ember/{-internals/routing/lib/system → routing/lib}/dsl.js +0 -0
  76. package/dist/packages/@ember/{-internals/routing/lib/system → routing/lib}/engines.js +0 -0
  77. package/dist/packages/@ember/{-internals/routing/lib/system → routing/lib}/generate_controller.js +0 -0
  78. package/dist/packages/@ember/{-internals/routing/lib/location/util.js → routing/lib/location-utils.js} +0 -0
  79. package/dist/packages/@ember/{-internals/routing/lib/system → routing/lib}/query_params.js +0 -0
  80. package/dist/packages/@ember/{-internals/routing/lib/system → routing/lib}/route-info.js +0 -0
  81. package/dist/packages/@ember/{-internals/routing/lib/system → routing/lib}/router_state.js +1 -1
  82. package/dist/packages/@ember/{-internals/routing/lib/services/routing.js → routing/lib/routing-service.js} +2 -2
  83. package/dist/packages/@ember/{-internals/routing/lib/system → routing/lib}/transition.js +0 -0
  84. package/dist/packages/@ember/{-internals/routing → routing}/lib/utils.js +0 -0
  85. package/dist/packages/@ember/routing/location.js +104 -1
  86. package/dist/packages/@ember/routing/none-location.js +123 -1
  87. package/dist/packages/@ember/routing/route.js +1700 -1
  88. package/dist/packages/@ember/routing/router-service.js +510 -1
  89. package/dist/packages/@ember/routing/router.js +1666 -1
  90. package/dist/packages/@ember/service/index.js +1 -1
  91. package/dist/packages/@ember/utils/index.js +7 -2
  92. package/dist/packages/@ember/{-internals/runtime → utils}/lib/compare.js +2 -2
  93. package/dist/packages/@ember/{-internals/runtime → utils}/lib/is-equal.js +0 -0
  94. package/dist/packages/@ember/utils/lib/is_blank.js +35 -0
  95. package/dist/packages/@ember/utils/lib/is_empty.js +68 -0
  96. package/dist/packages/@ember/utils/lib/is_none.js +27 -0
  97. package/dist/packages/@ember/utils/lib/is_present.js +38 -0
  98. package/dist/packages/@ember/{-internals/runtime → utils}/lib/type-of.js +2 -2
  99. package/dist/packages/ember/index.js +47 -28
  100. package/dist/packages/ember/version.js +1 -1
  101. package/dist/packages/ember-testing/lib/adapters/adapter.js +1 -1
  102. package/dist/packages/ember-testing/lib/helpers/current_path.js +2 -2
  103. package/dist/packages/ember-testing/lib/helpers/current_route_name.js +2 -2
  104. package/dist/packages/ember-testing/lib/helpers/current_url.js +1 -1
  105. package/docs/data.json +9428 -9189
  106. package/package.json +23 -8
  107. package/types/preview/@ember/-internals/resolver.d.ts +35 -0
  108. package/types/preview/@ember/application/-private/event-dispatcher.d.ts +18 -0
  109. package/types/preview/@ember/application/-private/registry.d.ts +15 -0
  110. package/types/preview/@ember/application/deprecations.d.ts +24 -0
  111. package/types/preview/@ember/application/index.d.ts +153 -0
  112. package/types/preview/@ember/application/instance.d.ts +9 -0
  113. package/types/preview/@ember/application/tsconfig.json +3 -0
  114. package/types/preview/@ember/application/types.d.ts +29 -0
  115. package/types/preview/@ember/array/-private/enumerable.d.ts +13 -0
  116. package/types/preview/@ember/array/-private/mutable-enumerable.d.ts +13 -0
  117. package/types/preview/@ember/array/-private/native-array.d.ts +23 -0
  118. package/types/preview/@ember/array/index.d.ts +243 -0
  119. package/types/preview/@ember/array/mutable.d.ts +94 -0
  120. package/types/preview/@ember/array/proxy.d.ts +29 -0
  121. package/types/preview/@ember/array/tsconfig.json +3 -0
  122. package/types/preview/@ember/component/-private/class-names-support.d.ts +27 -0
  123. package/types/preview/@ember/component/-private/core-view.d.ts +14 -0
  124. package/types/preview/@ember/component/-private/glimmer-interfaces.d.ts +45 -0
  125. package/types/preview/@ember/component/-private/signature-utils.d.ts +107 -0
  126. package/types/preview/@ember/component/-private/view-mixin.d.ts +59 -0
  127. package/types/preview/@ember/component/helper.d.ts +122 -0
  128. package/types/preview/@ember/component/index.d.ts +132 -0
  129. package/types/preview/@ember/component/template-only.d.ts +47 -0
  130. package/types/preview/@ember/component/tsconfig.json +3 -0
  131. package/types/preview/@ember/controller/index.d.ts +48 -0
  132. package/types/preview/@ember/controller/tsconfig.json +3 -0
  133. package/types/preview/@ember/debug/container-debug-adapter.d.ts +13 -0
  134. package/types/preview/@ember/debug/data-adapter.d.ts +64 -0
  135. package/types/preview/@ember/debug/index.d.ts +98 -0
  136. package/types/preview/@ember/debug/tsconfig.json +3 -0
  137. package/types/preview/@ember/destroyable/index.d.ts +23 -0
  138. package/types/preview/@ember/destroyable/tsconfig.json +3 -0
  139. package/types/preview/@ember/engine/-private/container-proxy-mixin.d.ts +17 -0
  140. package/types/preview/@ember/engine/-private/registry-proxy-mixin.d.ts +54 -0
  141. package/types/preview/@ember/engine/-private/types/initializer.d.ts +8 -0
  142. package/types/preview/@ember/engine/index.d.ts +45 -0
  143. package/types/preview/@ember/engine/instance.d.ts +24 -0
  144. package/types/preview/@ember/engine/tsconfig.json +3 -0
  145. package/types/preview/@ember/error/index.d.ts +6 -0
  146. package/types/preview/@ember/error/tsconfig.json +3 -0
  147. package/types/preview/@ember/helper/index.d.ts +49 -0
  148. package/types/preview/@ember/helper/tsconfig.json +3 -0
  149. package/types/preview/@ember/modifier/index.d.ts +33 -0
  150. package/types/preview/@ember/modifier/tsconfig.json +3 -0
  151. package/types/preview/@ember/object/-private/action-handler.d.ts +31 -0
  152. package/types/preview/@ember/object/-private/types.d.ts +63 -0
  153. package/types/preview/@ember/object/compat.d.ts +9 -0
  154. package/types/preview/@ember/object/computed.d.ts +263 -0
  155. package/types/preview/@ember/object/core.d.ts +89 -0
  156. package/types/preview/@ember/object/evented.d.ts +45 -0
  157. package/types/preview/@ember/object/events.d.ts +47 -0
  158. package/types/preview/@ember/object/index.d.ts +126 -0
  159. package/types/preview/@ember/object/internals.d.ts +17 -0
  160. package/types/preview/@ember/object/mixin.d.ts +19 -0
  161. package/types/preview/@ember/object/observable.d.ts +89 -0
  162. package/types/preview/@ember/object/observers.d.ts +34 -0
  163. package/types/preview/@ember/object/promise-proxy-mixin.d.ts +37 -0
  164. package/types/preview/@ember/object/proxy.d.ts +27 -0
  165. package/types/preview/@ember/object/tsconfig.json +3 -0
  166. package/types/preview/@ember/owner/index.d.ts +102 -0
  167. package/types/preview/@ember/owner/tsconfig.json +3 -0
  168. package/types/preview/@ember/polyfills/index.d.ts +23 -0
  169. package/types/preview/@ember/polyfills/tsconfig.json +3 -0
  170. package/types/preview/@ember/polyfills/types.d.ts +6 -0
  171. package/types/preview/@ember/routing/-private/router-dsl.d.ts +20 -0
  172. package/types/preview/@ember/routing/auto-location.d.ts +8 -0
  173. package/types/preview/@ember/routing/hash-location.d.ts +10 -0
  174. package/types/preview/@ember/routing/history-location.d.ts +9 -0
  175. package/types/preview/@ember/routing/index.d.ts +20 -0
  176. package/types/preview/@ember/routing/none-location.d.ts +11 -0
  177. package/types/preview/@ember/routing/route-info.d.ts +74 -0
  178. package/types/preview/@ember/routing/route.d.ts +533 -0
  179. package/types/preview/@ember/routing/router-service.d.ts +351 -0
  180. package/types/preview/@ember/routing/router.d.ts +49 -0
  181. package/types/preview/@ember/routing/transition.d.ts +126 -0
  182. package/types/preview/@ember/routing/tsconfig.json +3 -0
  183. package/types/preview/@ember/routing/types.d.ts +15 -0
  184. package/types/preview/@ember/runloop/-private/backburner.d.ts +43 -0
  185. package/types/preview/@ember/runloop/-private/types.d.ts +9 -0
  186. package/types/preview/@ember/runloop/index.d.ts +175 -0
  187. package/types/preview/@ember/runloop/tsconfig.json +3 -0
  188. package/types/preview/@ember/runloop/types.d.ts +5 -0
  189. package/types/preview/@ember/service/index.d.ts +25 -0
  190. package/types/preview/@ember/service/tsconfig.json +3 -0
  191. package/types/preview/@ember/string/index.d.ts +9 -0
  192. package/types/preview/@ember/string/tsconfig.json +3 -0
  193. package/types/preview/@ember/template/-private/handlebars.d.ts +7 -0
  194. package/types/preview/@ember/template/index.d.ts +5 -0
  195. package/types/preview/@ember/template/tsconfig.json +3 -0
  196. package/types/preview/@ember/test/adapter.d.ts +22 -0
  197. package/types/preview/@ember/test/index.d.ts +49 -0
  198. package/types/preview/@ember/test/tsconfig.json +3 -0
  199. package/types/preview/@ember/utils/-private/types.d.ts +39 -0
  200. package/types/preview/@ember/utils/index.d.ts +42 -0
  201. package/types/preview/@ember/utils/tsconfig.json +3 -0
  202. package/types/preview/ember/-private/type-utils.d.ts +54 -0
  203. package/types/preview/ember/index.d.ts +381 -0
  204. package/types/preview/ember/tsconfig.json +3 -0
  205. package/types/preview/index.d.ts +120 -0
  206. package/types/preview/tsconfig.json +6 -0
  207. package/blueprints/helper/mu-files/__root__/__collection__/__name__.js +0 -7
  208. package/blueprints-js/helper/mu-files/__root__/__collection__/__name__.js +0 -7
  209. package/dist/packages/@ember/-internals/extension-support/index.js +0 -2
  210. package/dist/packages/@ember/-internals/extension-support/lib/container_debug_adapter.js +0 -96
  211. package/dist/packages/@ember/-internals/extension-support/lib/data_adapter.js +0 -576
  212. package/dist/packages/@ember/-internals/routing/lib/ext/controller.js +0 -224
  213. package/dist/packages/@ember/-internals/routing/lib/location/api.js +0 -104
  214. package/dist/packages/@ember/-internals/routing/lib/location/auto_location.js +0 -250
  215. package/dist/packages/@ember/-internals/routing/lib/location/hash_location.js +0 -170
  216. package/dist/packages/@ember/-internals/routing/lib/location/history_location.js +0 -290
  217. package/dist/packages/@ember/-internals/routing/lib/location/none_location.js +0 -124
  218. package/dist/packages/@ember/-internals/routing/lib/services/router.js +0 -506
  219. package/dist/packages/@ember/-internals/routing/lib/system/route.js +0 -1696
  220. package/dist/packages/@ember/-internals/routing/lib/system/router.js +0 -1662
  221. package/dist/packages/@ember/-internals/runtime/lib/mixins/array.js +0 -1501
  222. package/dist/packages/@ember/-internals/runtime/lib/mixins/enumerable.js +0 -3
  223. package/dist/packages/@ember/-internals/runtime/lib/mixins/evented.js +0 -91
  224. package/dist/packages/@ember/-internals/runtime/lib/mixins/mutable_enumerable.js +0 -4
  225. package/dist/packages/@ember/-internals/runtime/lib/mixins/observable.js +0 -339
  226. package/dist/packages/@ember/-internals/runtime/lib/mixins/promise_proxy.js +0 -149
  227. package/dist/packages/@ember/-internals/runtime/lib/system/array_proxy.js +0 -305
  228. package/dist/packages/@ember/-internals/runtime/lib/system/core_object.js +0 -730
  229. package/dist/packages/@ember/-internals/runtime/lib/system/namespace.js +0 -69
  230. package/dist/packages/@ember/-internals/runtime/lib/system/object_proxy.js +0 -7
  231. package/dist/packages/@ember/application/lib/application.js +0 -870
  232. package/dist/packages/@ember/controller/lib/controller_mixin.js +0 -42
  233. package/dist/packages/@ember/runloop/type-tests.ts/begin-end.test.js +0 -5
  234. package/dist/packages/@ember/runloop/type-tests.ts/bind.test.js +0 -59
  235. package/dist/packages/@ember/runloop/type-tests.ts/cancel.test.js +0 -5
  236. package/dist/packages/@ember/runloop/type-tests.ts/debounce.test.js +0 -77
  237. package/dist/packages/@ember/runloop/type-tests.ts/join.test.js +0 -38
  238. package/dist/packages/@ember/runloop/type-tests.ts/later.test.js +0 -38
  239. package/dist/packages/@ember/runloop/type-tests.ts/next.test.js +0 -38
  240. package/dist/packages/@ember/runloop/type-tests.ts/once.test.js +0 -38
  241. package/dist/packages/@ember/runloop/type-tests.ts/run.test.js +0 -38
  242. package/dist/packages/@ember/runloop/type-tests.ts/schedule-once.test.js +0 -39
  243. package/dist/packages/@ember/runloop/type-tests.ts/schedule.test.js +0 -39
  244. package/dist/packages/@ember/runloop/type-tests.ts/throttle.test.js +0 -77
@@ -1,3 +1,877 @@
1
+ /**
2
+ @module @ember/application
3
+ */
1
4
  export { getOwner, setOwner } from '@ember/-internals/owner';
2
- export { onLoad, runLoadHooks, _loaded } from './lib/lazy_load';
3
- export { default } from './lib/application';
5
+ import { dictionary } from '@ember/-internals/utils';
6
+ import { ENV } from '@ember/-internals/environment';
7
+ import { hasDOM } from '@ember/-internals/browser-environment';
8
+ import { assert } from '@ember/debug';
9
+ import { DEBUG } from '@glimmer/env';
10
+ import { join, once, run, schedule } from '@ember/runloop';
11
+ import { libraries } from '@ember/-internals/metal';
12
+ import { _loaded, onLoad, runLoadHooks } from './lib/lazy_load';
13
+ import { RSVP } from '@ember/-internals/runtime';
14
+ import { EventDispatcher } from '@ember/-internals/views';
15
+ import Route from '@ember/routing/route';
16
+ import Router from '@ember/routing/router';
17
+ import AutoLocation from '@ember/routing/auto-location';
18
+ import HashLocation from '@ember/routing/hash-location';
19
+ import HistoryLocation from '@ember/routing/history-location';
20
+ import NoneLocation from '@ember/routing/none-location';
21
+ import { BucketCache } from '@ember/routing/-internals';
22
+ import ApplicationInstance from '@ember/application/instance';
23
+ import Engine, { buildInitializerMethod } from '@ember/engine';
24
+ import { privatize as P } from '@ember/-internals/container';
25
+ import { setupApplicationRegistry } from '@ember/-internals/glimmer';
26
+ import RouterService from '@ember/routing/router-service';
27
+ /**
28
+ An instance of `Application` is the starting point for every Ember
29
+ application. It instantiates, initializes and coordinates the
30
+ objects that make up your app.
31
+
32
+ Each Ember app has one and only one `Application` object. Although
33
+ Ember CLI creates this object implicitly, the `Application` class
34
+ is defined in the `app/app.js`. You can define a `ready` method on the
35
+ `Application` class, which will be run by Ember when the application is
36
+ initialized.
37
+
38
+ ```app/app.js
39
+ export default class App extends Application {
40
+ ready() {
41
+ // your code here
42
+ }
43
+ }
44
+ ```
45
+
46
+ Because `Application` ultimately inherits from `Ember.Namespace`, any classes
47
+ you create will have useful string representations when calling `toString()`.
48
+ See the `Ember.Namespace` documentation for more information.
49
+
50
+ While you can think of your `Application` as a container that holds the
51
+ other classes in your application, there are several other responsibilities
52
+ going on under-the-hood that you may want to understand. It is also important
53
+ to understand that an `Application` is different from an `ApplicationInstance`.
54
+ Refer to the Guides to understand the difference between these.
55
+
56
+ ### Event Delegation
57
+
58
+ Ember uses a technique called _event delegation_. This allows the framework
59
+ to set up a global, shared event listener instead of requiring each view to
60
+ do it manually. For example, instead of each view registering its own
61
+ `mousedown` listener on its associated element, Ember sets up a `mousedown`
62
+ listener on the `body`.
63
+
64
+ If a `mousedown` event occurs, Ember will look at the target of the event and
65
+ start walking up the DOM node tree, finding corresponding views and invoking
66
+ their `mouseDown` method as it goes.
67
+
68
+ `Application` has a number of default events that it listens for, as
69
+ well as a mapping from lowercase events to camel-cased view method names. For
70
+ example, the `keypress` event causes the `keyPress` method on the view to be
71
+ called, the `dblclick` event causes `doubleClick` to be called, and so on.
72
+
73
+ If there is a bubbling browser event that Ember does not listen for by
74
+ default, you can specify custom events and their corresponding view method
75
+ names by setting the application's `customEvents` property:
76
+
77
+ ```app/app.js
78
+ import Application from '@ember/application';
79
+
80
+ export default class App extends Application {
81
+ customEvents = {
82
+ // add support for the paste event
83
+ paste: 'paste'
84
+ }
85
+ }
86
+ ```
87
+
88
+ To prevent Ember from setting up a listener for a default event,
89
+ specify the event name with a `null` value in the `customEvents`
90
+ property:
91
+
92
+ ```app/app.js
93
+ import Application from '@ember/application';
94
+
95
+ export default class App extends Application {
96
+ customEvents = {
97
+ // prevent listeners for mouseenter/mouseleave events
98
+ mouseenter: null,
99
+ mouseleave: null
100
+ }
101
+ }
102
+ ```
103
+
104
+ By default, the application sets up these event listeners on the document
105
+ body. However, in cases where you are embedding an Ember application inside
106
+ an existing page, you may want it to set up the listeners on an element
107
+ inside the body.
108
+
109
+ For example, if only events inside a DOM element with the ID of `ember-app`
110
+ should be delegated, set your application's `rootElement` property:
111
+
112
+ ```app/app.js
113
+ import Application from '@ember/application';
114
+
115
+ export default class App extends Application {
116
+ rootElement = '#ember-app'
117
+ }
118
+ ```
119
+
120
+ The `rootElement` can be either a DOM element or a CSS selector
121
+ string. Note that *views appended to the DOM outside the root element will
122
+ not receive events.* If you specify a custom root element, make sure you only
123
+ append views inside it!
124
+
125
+ To learn more about the events Ember components use, see
126
+
127
+ [components/handling-events](https://guides.emberjs.com/release/components/handling-events/#toc_event-names).
128
+
129
+ ### Initializers
130
+
131
+ To add behavior to the Application's boot process, you can define initializers in
132
+ the `app/initializers` directory, or with `ember generate initializer` using Ember CLI.
133
+ These files should export a named `initialize` function which will receive the created `application`
134
+ object as its first argument.
135
+
136
+ ```javascript
137
+ export function initialize(application) {
138
+ // application.inject('route', 'foo', 'service:foo');
139
+ }
140
+ ```
141
+
142
+ Application initializers can be used for a variety of reasons including:
143
+
144
+ - setting up external libraries
145
+ - injecting dependencies
146
+ - setting up event listeners in embedded apps
147
+ - deferring the boot process using the `deferReadiness` and `advanceReadiness` APIs.
148
+
149
+ ### Routing
150
+
151
+ In addition to creating your application's router, `Application` is
152
+ also responsible for telling the router when to start routing. Transitions
153
+ between routes can be logged with the `LOG_TRANSITIONS` flag, and more
154
+ detailed intra-transition logging can be logged with
155
+ the `LOG_TRANSITIONS_INTERNAL` flag:
156
+
157
+ ```javascript
158
+ import Application from '@ember/application';
159
+
160
+ let App = Application.create({
161
+ LOG_TRANSITIONS: true, // basic logging of successful transitions
162
+ LOG_TRANSITIONS_INTERNAL: true // detailed logging of all routing steps
163
+ });
164
+ ```
165
+
166
+ By default, the router will begin trying to translate the current URL into
167
+ application state once the browser emits the `DOMContentReady` event. If you
168
+ need to defer routing, you can call the application's `deferReadiness()`
169
+ method. Once routing can begin, call the `advanceReadiness()` method.
170
+
171
+ If there is any setup required before routing begins, you can implement a
172
+ `ready()` method on your app that will be invoked immediately before routing
173
+ begins.
174
+
175
+ @class Application
176
+ @extends Engine
177
+ @public
178
+ */
179
+
180
+ class Application extends Engine {
181
+ constructor() {
182
+ super(...arguments);
183
+ this._bootPromise = null;
184
+ this._bootResolver = null;
185
+ }
186
+ /**
187
+ This creates a registry with the default Ember naming conventions.
188
+ It also configures the registry:
189
+ * registered views are created every time they are looked up (they are
190
+ not singletons)
191
+ * registered templates are not factories; the registered value is
192
+ returned directly.
193
+ * the router receives the application as its `namespace` property
194
+ * all controllers receive the router as their `target` and `controllers`
195
+ properties
196
+ * all controllers receive the application as their `namespace` property
197
+ * the application view receives the application controller as its
198
+ `controller` property
199
+ * the application view receives the application template as its
200
+ `defaultTemplate` property
201
+ @method buildRegistry
202
+ @static
203
+ @param {Application} namespace the application for which to
204
+ build the registry
205
+ @return {Ember.Registry} the built registry
206
+ @private
207
+ */
208
+
209
+
210
+ static buildRegistry(namespace) {
211
+ let registry = super.buildRegistry(namespace);
212
+ commonSetupRegistry(registry);
213
+ setupApplicationRegistry(registry);
214
+ return registry;
215
+ }
216
+
217
+ init(properties) {
218
+ var _a, _b, _c, _d, _e, _f, _g, _h;
219
+
220
+ super.init(properties);
221
+ (_a = this.rootElement) !== null && _a !== void 0 ? _a : this.rootElement = 'body';
222
+ (_b = this._document) !== null && _b !== void 0 ? _b : this._document = null;
223
+ (_c = this.eventDispatcher) !== null && _c !== void 0 ? _c : this.eventDispatcher = null;
224
+ (_d = this.customEvents) !== null && _d !== void 0 ? _d : this.customEvents = null;
225
+ (_e = this.autoboot) !== null && _e !== void 0 ? _e : this.autoboot = true;
226
+ (_f = this._document) !== null && _f !== void 0 ? _f : this._document = hasDOM ? window.document : null;
227
+ (_g = this._globalsMode) !== null && _g !== void 0 ? _g : this._globalsMode = true;
228
+
229
+ if (DEBUG) {
230
+ if (ENV.LOG_VERSION) {
231
+ // we only need to see this once per Application#init
232
+ ENV.LOG_VERSION = false;
233
+ (_h = libraries.logVersions) === null || _h === void 0 ? void 0 : _h.call(libraries);
234
+ }
235
+ } // Start off the number of deferrals at 1. This will be decremented by
236
+ // the Application's own `boot` method.
237
+
238
+
239
+ this._readinessDeferrals = 1;
240
+ this._booted = false;
241
+ this._applicationInstances = new Set();
242
+ this.autoboot = this._globalsMode = Boolean(this.autoboot);
243
+
244
+ if (this._globalsMode) {
245
+ this._prepareForGlobalsMode();
246
+ }
247
+
248
+ if (this.autoboot) {
249
+ this.waitForDOMReady();
250
+ }
251
+ }
252
+ /**
253
+ Create an ApplicationInstance for this application.
254
+ @public
255
+ @method buildInstance
256
+ @return {ApplicationInstance} the application instance
257
+ */
258
+
259
+
260
+ buildInstance(options = {}) {
261
+ assert('You cannot build new instances of this application since it has already been destroyed', !this.isDestroyed);
262
+ assert('You cannot build new instances of this application since it is being destroyed', !this.isDestroying);
263
+ return ApplicationInstance.create(Object.assign(Object.assign({}, options), {
264
+ base: this,
265
+ application: this
266
+ }));
267
+ }
268
+ /**
269
+ Start tracking an ApplicationInstance for this application.
270
+ Used when the ApplicationInstance is created.
271
+ @private
272
+ @method _watchInstance
273
+ */
274
+
275
+
276
+ _watchInstance(instance) {
277
+ this._applicationInstances.add(instance);
278
+ }
279
+ /**
280
+ Stop tracking an ApplicationInstance for this application.
281
+ Used when the ApplicationInstance is about to be destroyed.
282
+ @private
283
+ @method _unwatchInstance
284
+ */
285
+
286
+
287
+ _unwatchInstance(instance) {
288
+ return this._applicationInstances.delete(instance);
289
+ }
290
+ /**
291
+ Enable the legacy globals mode by allowing this application to act
292
+ as a global namespace. See the docs on the `_globalsMode` property
293
+ for details.
294
+ Most of these features are already deprecated in 1.x, so we can
295
+ stop using them internally and try to remove them.
296
+ @private
297
+ @method _prepareForGlobalsMode
298
+ */
299
+
300
+
301
+ _prepareForGlobalsMode() {
302
+ // Create subclass of Router for this Application instance.
303
+ // This is to ensure that someone reopening `App.Router` does not
304
+ // tamper with the default `Router`.
305
+ this.Router = (this.Router || Router).extend();
306
+
307
+ this._buildDeprecatedInstance();
308
+ }
309
+ /*
310
+ Build the deprecated instance for legacy globals mode support.
311
+ Called when creating and resetting the application.
312
+ This is orthogonal to autoboot: the deprecated instance needs to
313
+ be created at Application construction (not boot) time to expose
314
+ App.__container__. If autoboot sees that this instance exists,
315
+ it will continue booting it to avoid doing unncessary work (as
316
+ opposed to building a new instance at boot time), but they are
317
+ otherwise unrelated.
318
+ @private
319
+ @method _buildDeprecatedInstance
320
+ */
321
+
322
+
323
+ _buildDeprecatedInstance() {
324
+ // Build a default instance
325
+ let instance = this.buildInstance(); // Legacy support for App.__container__ and other global methods
326
+ // on App that rely on a single, default instance.
327
+
328
+ this.__deprecatedInstance__ = instance;
329
+ this.__container__ = instance.__container__;
330
+ }
331
+ /**
332
+ Automatically kick-off the boot process for the application once the
333
+ DOM has become ready.
334
+ The initialization itself is scheduled on the actions queue which
335
+ ensures that code-loading finishes before booting.
336
+ If you are asynchronously loading code, you should call `deferReadiness()`
337
+ to defer booting, and then call `advanceReadiness()` once all of your code
338
+ has finished loading.
339
+ @private
340
+ @method waitForDOMReady
341
+ */
342
+
343
+
344
+ waitForDOMReady() {
345
+ const document = this._document; // SAFETY: Casting as Document should be safe since we're just reading a property.
346
+ // If it's not actually a Document then it will evaluate false which is fine for our
347
+ // purposes.
348
+
349
+ if (document === null || document.readyState !== 'loading') {
350
+ schedule('actions', this, this.domReady);
351
+ } else {
352
+ // Ideally we'd just check `document instanceof Document` but currently some tests pass a fake document.
353
+ assert('[BUG] Called waitForDOMReady with an invalid document', function (d) {
354
+ return typeof d.removeEventListener === 'function';
355
+ }(document));
356
+
357
+ let callback = () => {
358
+ document.removeEventListener('DOMContentLoaded', callback);
359
+ run(this, this.domReady);
360
+ };
361
+
362
+ document.addEventListener('DOMContentLoaded', callback);
363
+ }
364
+ }
365
+ /**
366
+ This is the autoboot flow:
367
+ 1. Boot the app by calling `this.boot()`
368
+ 2. Create an instance (or use the `__deprecatedInstance__` in globals mode)
369
+ 3. Boot the instance by calling `instance.boot()`
370
+ 4. Invoke the `App.ready()` callback
371
+ 5. Kick-off routing on the instance
372
+ Ideally, this is all we would need to do:
373
+ ```javascript
374
+ _autoBoot() {
375
+ this.boot().then(() => {
376
+ let instance = (this._globalsMode) ? this.__deprecatedInstance__ : this.buildInstance();
377
+ return instance.boot();
378
+ }).then((instance) => {
379
+ App.ready();
380
+ instance.startRouting();
381
+ });
382
+ }
383
+ ```
384
+ Unfortunately, we cannot actually write this because we need to participate
385
+ in the "synchronous" boot process. While the code above would work fine on
386
+ the initial boot (i.e. DOM ready), when `App.reset()` is called, we need to
387
+ boot a new instance synchronously (see the documentation on `_bootSync()`
388
+ for details).
389
+ Because of this restriction, the actual logic of this method is located
390
+ inside `didBecomeReady()`.
391
+ @private
392
+ @method domReady
393
+ */
394
+
395
+
396
+ domReady() {
397
+ if (this.isDestroying || this.isDestroyed) {
398
+ return;
399
+ }
400
+
401
+ this._bootSync(); // Continues to `didBecomeReady`
402
+
403
+ }
404
+ /**
405
+ Use this to defer readiness until some condition is true.
406
+ Example:
407
+ ```javascript
408
+ import Application from '@ember/application';
409
+ let App = Application.create();
410
+ App.deferReadiness();
411
+ fetch('/auth-token')
412
+ .then(response => response.json())
413
+ .then(data => {
414
+ App.token = data.token;
415
+ App.advanceReadiness();
416
+ });
417
+ ```
418
+ This allows you to perform asynchronous setup logic and defer
419
+ booting your application until the setup has finished.
420
+ However, if the setup requires a loading UI, it might be better
421
+ to use the router for this purpose.
422
+ @method deferReadiness
423
+ @public
424
+ */
425
+
426
+
427
+ deferReadiness() {
428
+ assert('You must call deferReadiness on an instance of Application', this instanceof Application);
429
+ assert('You cannot defer readiness since application has already destroyed', !this.isDestroyed);
430
+ assert('You cannot defer readiness since the application is being destroyed', !this.isDestroying);
431
+ assert('You cannot defer readiness since the `ready()` hook has already been called', this._readinessDeferrals > 0);
432
+ this._readinessDeferrals++;
433
+ }
434
+ /**
435
+ Call `advanceReadiness` after any asynchronous setup logic has completed.
436
+ Each call to `deferReadiness` must be matched by a call to `advanceReadiness`
437
+ or the application will never become ready and routing will not begin.
438
+ @method advanceReadiness
439
+ @see {Application#deferReadiness}
440
+ @public
441
+ */
442
+
443
+
444
+ advanceReadiness() {
445
+ assert('You must call advanceReadiness on an instance of Application', this instanceof Application);
446
+ assert('You cannot advance readiness since application has already destroyed', !this.isDestroyed);
447
+ assert('You cannot advance readiness since the application is being destroyed', !this.isDestroying);
448
+ assert('You cannot advance readiness since the `ready()` hook has already been called', this._readinessDeferrals > 0);
449
+ this._readinessDeferrals--;
450
+
451
+ if (this._readinessDeferrals === 0) {
452
+ once(this, this.didBecomeReady);
453
+ }
454
+ }
455
+ /**
456
+ Initialize the application and return a promise that resolves with the `Application`
457
+ object when the boot process is complete.
458
+ Run any application initializers and run the application load hook. These hooks may
459
+ choose to defer readiness. For example, an authentication hook might want to defer
460
+ readiness until the auth token has been retrieved.
461
+ By default, this method is called automatically on "DOM ready"; however, if autoboot
462
+ is disabled, this is automatically called when the first application instance is
463
+ created via `visit`.
464
+ @public
465
+ @method boot
466
+ @return {Promise<Application,Error>}
467
+ */
468
+
469
+
470
+ boot() {
471
+ assert('You cannot boot this application since it has already been destroyed', !this.isDestroyed);
472
+ assert('You cannot boot this application since it is being destroyed', !this.isDestroying);
473
+
474
+ if (this._bootPromise) {
475
+ return this._bootPromise;
476
+ }
477
+
478
+ try {
479
+ this._bootSync();
480
+ } catch (_) {// Ignore the error: in the asynchronous boot path, the error is already reflected
481
+ // in the promise rejection
482
+ }
483
+
484
+ assert('has boot promise', this._bootPromise);
485
+ return this._bootPromise;
486
+ }
487
+ /**
488
+ Unfortunately, a lot of existing code assumes the booting process is
489
+ "synchronous". Specifically, a lot of tests assumes the last call to
490
+ `app.advanceReadiness()` or `app.reset()` will result in the app being
491
+ fully-booted when the current runloop completes.
492
+ We would like new code (like the `visit` API) to stop making this assumption,
493
+ so we created the asynchronous version above that returns a promise. But until
494
+ we have migrated all the code, we would have to expose this method for use
495
+ *internally* in places where we need to boot an app "synchronously".
496
+ @private
497
+ */
498
+
499
+
500
+ _bootSync() {
501
+ if (this._booted || this.isDestroying || this.isDestroyed) {
502
+ return;
503
+ } // Even though this returns synchronously, we still need to make sure the
504
+ // boot promise exists for book-keeping purposes: if anything went wrong in
505
+ // the boot process, we need to store the error as a rejection on the boot
506
+ // promise so that a future caller of `boot()` can tell what failed.
507
+
508
+
509
+ let defer = this._bootResolver = RSVP.defer();
510
+ this._bootPromise = defer.promise;
511
+
512
+ try {
513
+ this.runInitializers();
514
+ runLoadHooks('application', this);
515
+ this.advanceReadiness(); // Continues to `didBecomeReady`
516
+ } catch (error) {
517
+ // For the asynchronous boot path
518
+ defer.reject(error); // For the synchronous boot path
519
+
520
+ throw error;
521
+ }
522
+ }
523
+ /**
524
+ Reset the application. This is typically used only in tests. It cleans up
525
+ the application in the following order:
526
+ 1. Deactivate existing routes
527
+ 2. Destroy all objects in the container
528
+ 3. Create a new application container
529
+ 4. Re-route to the existing url
530
+ Typical Example:
531
+ ```javascript
532
+ import Application from '@ember/application';
533
+ let App;
534
+ run(function() {
535
+ App = Application.create();
536
+ });
537
+ module('acceptance test', {
538
+ setup: function() {
539
+ App.reset();
540
+ }
541
+ });
542
+ test('first test', function() {
543
+ // App is freshly reset
544
+ });
545
+ test('second test', function() {
546
+ // App is again freshly reset
547
+ });
548
+ ```
549
+ Advanced Example:
550
+ Occasionally you may want to prevent the app from initializing during
551
+ setup. This could enable extra configuration, or enable asserting prior
552
+ to the app becoming ready.
553
+ ```javascript
554
+ import Application from '@ember/application';
555
+ let App;
556
+ run(function() {
557
+ App = Application.create();
558
+ });
559
+ module('acceptance test', {
560
+ setup: function() {
561
+ run(function() {
562
+ App.reset();
563
+ App.deferReadiness();
564
+ });
565
+ }
566
+ });
567
+ test('first test', function() {
568
+ ok(true, 'something before app is initialized');
569
+ run(function() {
570
+ App.advanceReadiness();
571
+ });
572
+ ok(true, 'something after app is initialized');
573
+ });
574
+ ```
575
+ @method reset
576
+ @public
577
+ */
578
+
579
+
580
+ reset() {
581
+ assert('You cannot reset this application since it has already been destroyed', !this.isDestroyed);
582
+ assert('You cannot reset this application since it is being destroyed', !this.isDestroying);
583
+ assert(`Calling reset() on instances of \`Application\` is not
584
+ supported when globals mode is disabled; call \`visit()\` to
585
+ create new \`ApplicationInstance\`s and dispose them
586
+ via their \`destroy()\` method instead.`, this._globalsMode && this.autoboot);
587
+ let instance = this.__deprecatedInstance__;
588
+ this._readinessDeferrals = 1;
589
+ this._bootPromise = null;
590
+ this._bootResolver = null;
591
+ this._booted = false;
592
+
593
+ function handleReset() {
594
+ assert('expected instance', instance);
595
+ run(instance, 'destroy');
596
+
597
+ this._buildDeprecatedInstance();
598
+
599
+ schedule('actions', this, '_bootSync');
600
+ }
601
+
602
+ join(this, handleReset);
603
+ }
604
+ /**
605
+ @private
606
+ @method didBecomeReady
607
+ */
608
+
609
+
610
+ didBecomeReady() {
611
+ if (this.isDestroying || this.isDestroyed) {
612
+ return;
613
+ }
614
+
615
+ assert('expected _bootResolver', this._bootResolver);
616
+
617
+ try {
618
+ // TODO: Is this still needed for _globalsMode = false?
619
+ // See documentation on `_autoboot()` for details
620
+ if (this.autoboot) {
621
+ let instance;
622
+
623
+ if (this._globalsMode) {
624
+ // If we already have the __deprecatedInstance__ lying around, boot it to
625
+ // avoid unnecessary work
626
+ instance = this.__deprecatedInstance__;
627
+ assert('expected instance', instance);
628
+ } else {
629
+ // Otherwise, build an instance and boot it. This is currently unreachable,
630
+ // because we forced _globalsMode to === autoboot; but having this branch
631
+ // allows us to locally toggle that flag for weeding out legacy globals mode
632
+ // dependencies independently
633
+ instance = this.buildInstance();
634
+ }
635
+
636
+ instance._bootSync(); // TODO: App.ready() is not called when autoboot is disabled, is this correct?
637
+
638
+
639
+ this.ready();
640
+ instance.startRouting();
641
+ } // For the asynchronous boot path
642
+
643
+
644
+ this._bootResolver.resolve(this); // For the synchronous boot path
645
+
646
+
647
+ this._booted = true;
648
+ } catch (error) {
649
+ // For the asynchronous boot path
650
+ this._bootResolver.reject(error); // For the synchronous boot path
651
+
652
+
653
+ throw error;
654
+ }
655
+ }
656
+ /**
657
+ Called when the Application has become ready, immediately before routing
658
+ begins. The call will be delayed until the DOM has become ready.
659
+ @event ready
660
+ @public
661
+ */
662
+
663
+
664
+ ready() {
665
+ return this;
666
+ } // This method must be moved to the application instance object
667
+
668
+
669
+ willDestroy() {
670
+ super.willDestroy();
671
+
672
+ if (_loaded['application'] === this) {
673
+ _loaded['application'] = undefined;
674
+ }
675
+
676
+ if (this._applicationInstances.size) {
677
+ this._applicationInstances.forEach(i => i.destroy());
678
+
679
+ this._applicationInstances.clear();
680
+ }
681
+ }
682
+ /**
683
+ Boot a new instance of `ApplicationInstance` for the current
684
+ application and navigate it to the given `url`. Returns a `Promise` that
685
+ resolves with the instance when the initial routing and rendering is
686
+ complete, or rejects with any error that occurred during the boot process.
687
+ When `autoboot` is disabled, calling `visit` would first cause the
688
+ application to boot, which runs the application initializers.
689
+ This method also takes a hash of boot-time configuration options for
690
+ customizing the instance's behavior. See the documentation on
691
+ `ApplicationInstance.BootOptions` for details.
692
+ `ApplicationInstance.BootOptions` is an interface class that exists
693
+ purely to document the available options; you do not need to construct it
694
+ manually. Simply pass a regular JavaScript object containing of the
695
+ desired options:
696
+ ```javascript
697
+ MyApp.visit("/", { location: "none", rootElement: "#container" });
698
+ ```
699
+ ### Supported Scenarios
700
+ While the `BootOptions` class exposes a large number of knobs, not all
701
+ combinations of them are valid; certain incompatible combinations might
702
+ result in unexpected behavior.
703
+ For example, booting the instance in the full browser environment
704
+ while specifying a foreign `document` object (e.g. `{ isBrowser: true,
705
+ document: iframe.contentDocument }`) does not work correctly today,
706
+ largely due to Ember's jQuery dependency.
707
+ Currently, there are three officially supported scenarios/configurations.
708
+ Usages outside of these scenarios are not guaranteed to work, but please
709
+ feel free to file bug reports documenting your experience and any issues
710
+ you encountered to help expand support.
711
+ #### Browser Applications (Manual Boot)
712
+ The setup is largely similar to how Ember works out-of-the-box. Normally,
713
+ Ember will boot a default instance for your Application on "DOM ready".
714
+ However, you can customize this behavior by disabling `autoboot`.
715
+ For example, this allows you to render a miniture demo of your application
716
+ into a specific area on your marketing website:
717
+ ```javascript
718
+ import MyApp from 'my-app';
719
+ $(function() {
720
+ let App = MyApp.create({ autoboot: false });
721
+ let options = {
722
+ // Override the router's location adapter to prevent it from updating
723
+ // the URL in the address bar
724
+ location: 'none',
725
+ // Override the default `rootElement` on the app to render into a
726
+ // specific `div` on the page
727
+ rootElement: '#demo'
728
+ };
729
+ // Start the app at the special demo URL
730
+ App.visit('/demo', options);
731
+ });
732
+ ```
733
+ Or perhaps you might want to boot two instances of your app on the same
734
+ page for a split-screen multiplayer experience:
735
+ ```javascript
736
+ import MyApp from 'my-app';
737
+ $(function() {
738
+ let App = MyApp.create({ autoboot: false });
739
+ let sessionId = MyApp.generateSessionID();
740
+ let player1 = App.visit(`/matches/join?name=Player+1&session=${sessionId}`, { rootElement: '#left', location: 'none' });
741
+ let player2 = App.visit(`/matches/join?name=Player+2&session=${sessionId}`, { rootElement: '#right', location: 'none' });
742
+ Promise.all([player1, player2]).then(() => {
743
+ // Both apps have completed the initial render
744
+ $('#loading').fadeOut();
745
+ });
746
+ });
747
+ ```
748
+ Do note that each app instance maintains their own registry/container, so
749
+ they will run in complete isolation by default.
750
+ #### Server-Side Rendering (also known as FastBoot)
751
+ This setup allows you to run your Ember app in a server environment using
752
+ Node.js and render its content into static HTML for SEO purposes.
753
+ ```javascript
754
+ const HTMLSerializer = new SimpleDOM.HTMLSerializer(SimpleDOM.voidMap);
755
+ function renderURL(url) {
756
+ let dom = new SimpleDOM.Document();
757
+ let rootElement = dom.body;
758
+ let options = { isBrowser: false, document: dom, rootElement: rootElement };
759
+ return MyApp.visit(options).then(instance => {
760
+ try {
761
+ return HTMLSerializer.serialize(rootElement.firstChild);
762
+ } finally {
763
+ instance.destroy();
764
+ }
765
+ });
766
+ }
767
+ ```
768
+ In this scenario, because Ember does not have access to a global `document`
769
+ object in the Node.js environment, you must provide one explicitly. In practice,
770
+ in the non-browser environment, the stand-in `document` object only needs to
771
+ implement a limited subset of the full DOM API. The `SimpleDOM` library is known
772
+ to work.
773
+ Since there is no DOM access in the non-browser environment, you must also
774
+ specify a DOM `Element` object in the same `document` for the `rootElement` option
775
+ (as opposed to a selector string like `"body"`).
776
+ See the documentation on the `isBrowser`, `document` and `rootElement` properties
777
+ on `ApplicationInstance.BootOptions` for details.
778
+ #### Server-Side Resource Discovery
779
+ This setup allows you to run the routing layer of your Ember app in a server
780
+ environment using Node.js and completely disable rendering. This allows you
781
+ to simulate and discover the resources (i.e. AJAX requests) needed to fulfill
782
+ a given request and eagerly "push" these resources to the client.
783
+ ```app/initializers/network-service.js
784
+ import BrowserNetworkService from 'app/services/network/browser';
785
+ import NodeNetworkService from 'app/services/network/node';
786
+ // Inject a (hypothetical) service for abstracting all AJAX calls and use
787
+ // the appropriate implementation on the client/server. This also allows the
788
+ // server to log all the AJAX calls made during a particular request and use
789
+ // that for resource-discovery purpose.
790
+ export function initialize(application) {
791
+ if (window) { // browser
792
+ application.register('service:network', BrowserNetworkService);
793
+ } else { // node
794
+ application.register('service:network', NodeNetworkService);
795
+ }
796
+ };
797
+ export default {
798
+ name: 'network-service',
799
+ initialize: initialize
800
+ };
801
+ ```
802
+ ```app/routes/post.js
803
+ import Route from '@ember/routing/route';
804
+ import { service } from '@ember/service';
805
+ // An example of how the (hypothetical) service is used in routes.
806
+ export default class IndexRoute extends Route {
807
+ @service network;
808
+ model(params) {
809
+ return this.network.fetch(`/api/posts/${params.post_id}.json`);
810
+ }
811
+ afterModel(post) {
812
+ if (post.isExternalContent) {
813
+ return this.network.fetch(`/api/external/?url=${post.externalURL}`);
814
+ } else {
815
+ return post;
816
+ }
817
+ }
818
+ }
819
+ ```
820
+ ```javascript
821
+ // Finally, put all the pieces together
822
+ function discoverResourcesFor(url) {
823
+ return MyApp.visit(url, { isBrowser: false, shouldRender: false }).then(instance => {
824
+ let networkService = instance.lookup('service:network');
825
+ return networkService.requests; // => { "/api/posts/123.json": "..." }
826
+ });
827
+ }
828
+ ```
829
+ @public
830
+ @method visit
831
+ @param url {String} The initial URL to navigate to
832
+ @param options {ApplicationInstance.BootOptions}
833
+ @return {Promise<ApplicationInstance, Error>}
834
+ */
835
+
836
+
837
+ visit(url, options) {
838
+ assert('You cannot visit this application since it has already been destroyed', !this.isDestroyed);
839
+ assert('You cannot visit this application since it is being destroyed', !this.isDestroying);
840
+ return this.boot().then(() => {
841
+ let instance = this.buildInstance();
842
+ return instance.boot(options).then(() => instance.visit(url)).catch(error => {
843
+ run(instance, 'destroy');
844
+ throw error;
845
+ });
846
+ });
847
+ }
848
+
849
+ }
850
+
851
+ Application.initializer = buildInitializerMethod('initializers', 'initializer');
852
+ Application.instanceInitializer = buildInitializerMethod('instanceInitializers', 'instance initializer');
853
+
854
+ function commonSetupRegistry(registry) {
855
+ registry.register('router:main', Router);
856
+ registry.register('-view-registry:main', {
857
+ create() {
858
+ return dictionary(null);
859
+ }
860
+
861
+ });
862
+ registry.register('route:basic', Route);
863
+ registry.register('event_dispatcher:main', EventDispatcher);
864
+ registry.register('location:auto', AutoLocation);
865
+ registry.register('location:hash', HashLocation);
866
+ registry.register('location:history', HistoryLocation);
867
+ registry.register('location:none', NoneLocation);
868
+ registry.register(P`-bucket-cache:main`, {
869
+ create() {
870
+ return new BucketCache();
871
+ }
872
+
873
+ });
874
+ registry.register('service:router', RouterService);
875
+ }
876
+
877
+ export { Application as default, _loaded, onLoad, runLoadHooks };