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