### Application Routing and Readiness Source: https://api.emberjs.com/ember/6.7/classes/Application This section explains how to control when the Ember.js application starts routing and how to manage asynchronous setup logic. ```APIDOC ## Application Configuration and Routing ### Description Configure application-level settings, including routing behavior and readiness management. You can enable transition logging for debugging. ### Method `Application.create(options)` ### Parameters #### Object `options` - **LOG_TRANSITIONS** (boolean) - Optional - Enables basic logging of successful route transitions. - **LOG_TRANSITIONS_INTERNAL** (boolean) - Optional - Enables detailed logging of all internal routing steps. ### Request Example ```javascript import Application from '@ember/application'; let App = Application.create({ LOG_TRANSITIONS: true, LOG_TRANSITIONS_INTERNAL: true }); ``` ### Response An Ember `Application` instance. * * * ## deferReadiness ### Description Defers the readiness of the application, preventing it from starting the routing process until `advanceReadiness` is called. ### Method `application.deferReadiness()` ### Endpoint N/A (Instance method) ### Parameters None ### Request Example ```javascript import Application from '@ember/application'; let App = Application.create(); App.deferReadiness(); fetch('/auth-token') .then(response => response.json()) .then(data => { App.token = data.token; App.advanceReadiness(); }); ``` ### Response None * * * ## advanceReadiness ### Description Advances the readiness of the application, allowing it to proceed with routing if readiness was previously deferred. ### Method `application.advanceReadiness()` ### Endpoint N/A (Instance method) ### Parameters None ### Request Example ```javascript // Assuming deferReadiness has been called previously App.advanceReadiness(); ``` ### Response None * * * ## boot ### Description Initializes the application, runs initializers and load hooks, and returns a promise that resolves when the application is fully booted. ### Method `application.boot(): Promise` ### Endpoint N/A (Instance method) ### Parameters None ### Request Example ```javascript App.boot().then(app => { console.log('Application booted successfully'); }).catch(error => { console.error('Application boot failed:', error); }); ``` ### Response #### Success Response (Promise resolves) - **Application** (`@ember/application`) - The booted application instance. #### Error Response (Promise rejects) - **Error** - An error object if the boot process fails. * * * ## buildInstance ### Description Creates and returns a new `ApplicationInstance` for the application. ### Method `application.buildInstance(): ApplicationInstance` ### Endpoint N/A (Instance method) ### Parameters None ### Request Example ```javascript const instance = App.buildInstance(); ``` ### Response #### Success Response - **ApplicationInstance** (`@ember/application/instance`) - A new application instance. ``` -------------------------------- ### Defer and Advance Ember.js Application Readiness Source: https://api.emberjs.com/ember/6.7/classes/Application This example illustrates how to manually control the readiness of an Ember.js application, typically for asynchronous setup tasks. It shows calling deferReadiness() to pause routing and advanceReadiness() to resume it after asynchronous operations like fetching data complete. This pattern is useful for ensuring all necessary setup is done before the application becomes fully interactive. ```javascript import Application from '@ember/application'; let App = Application.create(); App.deferReadiness(); fetch('/auth-token') .then(response => response.json()) .then(data => { App.token = data.token; App.advanceReadiness(); }); ``` -------------------------------- ### Initialize Instance with init Method (JavaScript) Source: https://api.emberjs.com/ember/6.7/classes/CoreObject Provides an example of overriding the init method to perform custom setup logic when an object instance is created. It highlights the importance of calling super.init in framework classes. ```javascript import EmberObject from '@ember/object'; const Person = EmberObject.extend({ init() { alert(`Name is ${this.get('name')}`); } }); let steve = Person.create({ name: 'Steve' }); // alerts 'Name is Steve'. ``` -------------------------------- ### Ember Get Property Example Source: https://api.emberjs.com/ember/6.7/classes/Service Demonstrates the usage of the `get` method to retrieve the value of a property from an Ember object. This method supports computed properties and unknown property handlers, providing a unified syntax for property access. ```javascript const value = this.get('propertyName'); ``` -------------------------------- ### ArrayProxy Usage Example - EmberJS Source: https://api.emberjs.com/ember/release/classes/ArrayProxy Demonstrates the basic usage of ArrayProxy to wrap an array and access its elements. It shows how to create an ArrayProxy, get the first object, and update the underlying content. ```javascript import { A } from '@ember/array'; import ArrayProxy from '@ember/array/proxy'; let pets = ['dog', 'cat', 'fish']; let ap = ArrayProxy.create({ content: A(pets) }); ap.get('firstObject'); // 'dog' ap.set('content', ['amoeba', 'paramecium']); ap.get('firstObject'); // 'amoeba' ``` -------------------------------- ### POST /init Source: https://api.emberjs.com/ember/release/classes/RouterService Initializes an object instance. This method can be overridden to perform custom setup during object instantiation. ```APIDOC ## POST /init ### Description An overridable method called when objects are instantiated. By default, does nothing unless it is overridden during class definition. ### Method POST ### Endpoint `/init` ### Parameters *No parameters required for the base `init` method.* ### Response #### Success Response (200) *This method typically does not return a value, but performs initialization tasks.* ### Note If overriding `init` for framework classes, remember to call `this._super(...arguments)`. ``` -------------------------------- ### JavaScript: Promise Example for findResult Source: https://api.emberjs.com/ember/release/classes/Promise A simple promise-based example demonstrating how to use the `then` method to handle the success and failure cases of the `findResult` operation. ```javascript findResult().then(function(result){ // success }, function(reason){ // failure }); ``` -------------------------------- ### boot Source: https://api.emberjs.com/ember/release/classes/EngineInstance Initializes the EngineInstance and starts the boot process, resolving with the instance itself upon completion. ```APIDOC ## POST /engine-instance/boot ### Description Initialize the `EngineInstance` and return a promise that resolves with the instance itself when the boot process is complete. The primary task here is to run any registered instance initializers. ### Method POST ### Endpoint `/engine-instance/boot` ### Parameters #### Request Body - **options** (Object) - Optional - Options for the boot process. See the documentation on `BootOptions`. ### Request Example ```json { "options": { "someOption": "value" } } ``` ### Response #### Success Response (200) - **EngineInstance** (Object) - The initialized EngineInstance. - **Error** (Object) - An error object if the boot process fails. #### Response Example ```json { "message": "EngineInstance booted successfully", "instanceId": "unique-instance-id" } ``` ``` -------------------------------- ### POST /websites/api_emberjs/init Source: https://api.emberjs.com/ember/6.7/classes/routerservice Initializes the object. This method can be overridden during class definition to perform custom setup. ```APIDOC ## POST init() ### Description An overridable method called when objects are instantiated. By default, does nothing unless it is overridden during class definition. ### Method POST ### Endpoint /websites/api_emberjs/init ### Parameters This endpoint does not require any parameters. ### Response #### Success Response (200) - **Object** - The initialized object. ### Response Example ```json { "status": "initialized" } ``` ``` -------------------------------- ### boot Method Source: https://api.emberjs.com/ember/release/classes/applicationinstance Information about the boot method, used to initialize the EngineInstance and start the application's run time. ```APIDOC ## boot(options) ### Description Initialize the `EngineInstance` and return a promise that resolves with the instance itself when the boot process is complete. The primary task here is to run any registered instance initializers. ### Method `boot` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None #### Parameters - **options** (Object) - Options for the boot process. See `BootOptions` documentation. ### Response #### Success Response (200) - **Promise** (Promise) - A promise that resolves with the instance itself upon completion of the boot process. ### Response Example ```json { "example": "Promise resolving with ApplicationInstance or an Error" } ``` ``` -------------------------------- ### Promise.all Usage with Multiple Promises Source: https://api.emberjs.com/ember/release/classes/Promise Provides examples of `Promise.all` with multiple Promises. The first example demonstrates successful fulfillment, resulting in an array of values. The second example shows rejection, where the `catch` handler receives the error from the first rejected promise. ```javascript import Promise, { resolve } from 'rsvp'; let promise1 = resolve(1); let promise2 = resolve(2); let promise3 = resolve(3); let promises = [ promise1, promise2, promise3 ]; Promise.all(promises).then(function(array){ // The array here would be [ 1, 2, 3 ]; }); ``` ```javascript import Promise, { resolve, reject } from 'rsvp'; let promise1 = resolve(1); let promise2 = reject(new Error("2")); let promise3 = reject(new Error("3")); let promises = [ promise1, promise2, promise3 ]; Promise.all(promises).then(function(array){ // Code here never runs because there are rejected promises! }, function(error) { // error.message === "2" }); ``` -------------------------------- ### Object Initialization API Source: https://api.emberjs.com/ember/6.7/classes/RouterService API for initializing Ember objects, allowing custom setup logic during instantiation. ```APIDOC ## POST /api/objects ### Description Initializes a new Ember object. This endpoint is intended for triggering the `init` method of an Ember object, allowing for custom setup logic during instantiation. ### Method POST ### Endpoint `/api/objects` ### Parameters #### Request Body - **objectType** (String) - Required - The type or class of the Ember object to instantiate. - **properties** (Object) - Optional - An object containing properties to initialize the object with. ### Request Example ```json { "objectType": "Person", "properties": { "name": "Steve" } } ``` ### Response #### Success Response (200) - **objectId** (String) - The identifier of the newly created object. #### Response Example ```json { "objectId": "new-object-123" } ``` ``` -------------------------------- ### JavaScript: Synchronous and Errback Examples Source: https://api.emberjs.com/ember/release/classes/Promise Provides examples of handling operations synchronously using try-catch blocks and asynchronously using the errback pattern (callbacks with error and success arguments). These illustrate alternative approaches to promise-based error handling. ```javascript let result; try { result = findResult(); // success } catch(reason) { // failure } ``` ```javascript findResult(function(result, err){ if (err) { // failure } else { // success } }); ``` -------------------------------- ### JavaScript: Advanced Synchronous and Errback Examples Source: https://api.emberjs.com/ember/release/classes/Promise Presents advanced synchronous (try-catch) and errback-style asynchronous handling for operations involving multiple steps, like finding an author and then their books. These examples highlight nested callbacks and error propagation in non-promise scenarios. ```javascript let author, books; try { author = findAuthor(); books = findBooksByAuthor(author); // success } catch(reason) { // failure } ``` ```javascript function foundBooks(books) { } function failure(reason) { } findAuthor(function(author, err){ if (err) { failure(err); // failure } else { try { findBoooksByAuthor(author, function(books, err) { if (err) { failure(err); } else { try { foundBooks(books); } catch(reason) { failure(reason); } } }); } catch(error) { failure(err); } // success } }); ``` -------------------------------- ### POST /initialize Source: https://api.emberjs.com/ember/release/classes/RouterService/properties/currentURL_anchor=currentRouteName Initializes an object. This method can be overridden during class definition for custom setup. ```APIDOC ## POST /initialize ### Description An overridable method called when objects are instantiated. By default, it does nothing unless overridden. ### Method POST ### Endpoint `/initialize` ### Parameters None ### Request Example ```json { "initializationData": {} } ``` ### Response #### Success Response (200) - **status** (String) - Indicates successful initialization. ### Response Example ```json { "status": "initialized" } ``` ``` -------------------------------- ### toString Method Example in EmberObject Source: https://api.emberjs.com/ember/release/classes/CoreObject Provides examples of the `toString` method, which returns a string representation of an Ember object. It can include class name, an Ember ID, and custom extensions defined by `toStringExtension`. ```javascript import EmberObject from '@ember/object'; const Person = EmberObject.extend(); let person = Person.create(); person.toString(); //=> "" ``` ```javascript const Student = Person.extend(); let student = Student.create(); student.toString(); //=> "<(subclass of Person):ember1025>" ``` ```javascript const Teacher = Person.extend({ toStringExtension() { return this.get('fullName'); } }); let teacher = Teacher.create({ fullName: 'Tom Dale' }); teacher.toString(); //=> "" ``` -------------------------------- ### Get Property Value Example (Ember.js) Source: https://api.emberjs.com/ember/6.7/classes/emberobject Demonstrates the use of the `get` method to retrieve the value of a property from an Ember object. This method is versatile as it handles computed properties and unknown property handlers. ```javascript const name = EmberObject.get(user, 'name'); ``` -------------------------------- ### Visit URL with Ember Application Instance Options Source: https://api.emberjs.com/ember/release/classes/application The `visit` method boots a new `ApplicationInstance` and navigates it to a specified URL. It returns a Promise that resolves with the instance or rejects with an error. Options can be passed to customize the boot process, such as `location` and `rootElement`. ```javascript MyApp.visit("/", { location: "none", rootElement: "#container" }); ``` ```javascript import MyApp from 'my-app'; $(function() { let App = MyApp.create({ autoboot: false }); let options = { // Override the router's location adapter to prevent it from updating // the URL in the address bar location: 'none', // Override the default `rootElement` on the app to render into a // specific `div` on the page rootElement: '#demo' }; // Start the app at the special demo URL App.visit('/demo', options); }); ``` ```javascript import MyApp from 'my-app'; $(function() { let App = MyApp.create({ autoboot: false }); let sessionId = MyApp.generateSessionID(); let player1 = App.visit(`/matches/join?name=Player+1&session=${sessionId}`, { rootElement: '#left', location: 'none' }); let player2 = App.visit(`/matches/join?name=Player+2&session=${sessionId}`, { rootElement: '#right', location: 'none' }); Promise.all([player1, player2]).then(() => { // Both apps have completed the initial render $('#loading').fadeOut(); }); }); ``` -------------------------------- ### Application Visit API Source: https://api.emberjs.com/ember/release/classes/application Boots a new instance of `ApplicationInstance` and navigates it to a specified URL. This method returns a Promise that resolves with the instance upon completion of initial routing and rendering, or rejects on error. It can also accept boot-time configuration options. ```APIDOC ## visit (url, options) ### Description Boots a new instance of `ApplicationInstance` for the current application and navigates it to the given `url`. Returns a `Promise` that resolves with the instance when the initial routing and rendering is complete, or rejects with any error that occurred during the boot process. When `autoboot` is disabled, calling `visit` would first cause the application to boot, which runs the application initializers. This method also takes a hash of boot-time configuration options for customizing the instance's behavior. ### Method (Implicitly called within test setup or manual boot scenarios, not a direct HTTP method) ### Endpoint (Not applicable, internal application method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body (Not applicable) ### Request Example ```javascript // Basic usage: MyApp.visit("/", { location: "none", rootElement: "#container" }); // With autoboot disabled for manual boot: import MyApp from 'my-app'; $(function() { let App = MyApp.create({ autoboot: false }); let options = { location: 'none', rootElement: '#demo' }; App.visit('/demo', options); }); ``` ### Response #### Success Response - **Promise** - A promise that resolves with the booted `ApplicationInstance` or rejects with an `Error`. #### Response Example (Not applicable, returns a Promise) ``` -------------------------------- ### EmberJS Concatenated Properties Example Source: https://api.emberjs.com/ember/release/classes/dataadapter Demonstrates how 'concatenatedProperties' allows properties to be combined from superclasses and subclasses rather than being overridden. This is useful for accumulating values like class names or bindings. The examples show the behavior with initial setup and during object creation. ```javascript import EmberObject from '@ember/object'; const Bar = EmberObject.extend({ // Configure which properties to concatenate concatenatedProperties: ['concatenatedProperty'], someNonConcatenatedProperty: ['bar'], concatenatedProperty: ['bar'] }); const FooBar = Bar.extend({ someNonConcatenatedProperty: ['foo'], concatenatedProperty: ['foo'] }); let fooBar = FooBar.create(); console.log(fooBar.get('someNonConcatenatedProperty')); // ['foo'] console.log(fooBar.get('concatenatedProperty')); // ['bar', 'foo'] let fooBarWithOverrides = FooBar.create({ someNonConcatenatedProperty: ['baz'], concatenatedProperty: ['baz'] }) console.log(fooBarWithOverrides.get('someNonConcatenatedProperty')); // ['baz'] console.log(fooBarWithOverrides.get('concatenatedProperty')); // ['bar', 'foo', 'baz'] let fooBarWithSingleValue = FooBar.create({ concatenatedProperty: 'baz' }) // Assuming 'view' is a typo and it should be fooBarWithSingleValue console.log(fooBarWithSingleValue.get('concatenatedProperty')); // ['bar', 'foo', 'baz'] ``` -------------------------------- ### Ember.js Manual Boot with Visit for Demo Source: https://api.emberjs.com/ember/6.7/classes/application Illustrates manually creating and booting an Ember.js application with `autoboot: false`, then using `visit` to render a miniature demo into a specific DOM element. This allows embedding Ember apps on marketing websites. ```javascript import MyApp from 'my-app'; $(function() { let App = MyApp.create({ autoboot: false }); let options = { // Override the router's location adapter to prevent it from updating // the URL in the address bar location: 'none', // Override the default `rootElement` on the app to render into a // specific `div` on the page rootElement: '#demo' }; // Start the app at the special demo URL App.visit('/demo', options); }); ``` -------------------------------- ### init Source: https://api.emberjs.com/ember/6.7/classes/Service An overridable method called when objects are instantiated. Useful for performing setup tasks during object creation. ```APIDOC ## INIT ### Description An overridable method called when objects are instantiated. By default, it does nothing unless overridden. ### Method `init()` ### Parameters None ### Request Example ```javascript import EmberObject from '@ember/object'; const Person = EmberObject.extend({ init() { alert(`Name is ${this.get('name')}`); } }); let steve = Person.create({ name: 'Steve' }); // alerts 'Name is Steve'. ``` ### Note If overriding `init` for framework classes (e.g., `Component`), remember to call `this._super(...arguments)` to ensure proper setup. ``` -------------------------------- ### Application Visit API Source: https://api.emberjs.com/ember/6.7/classes/Application The `visit` method boots a new instance of `ApplicationInstance` for the current application and navigates it to a specified URL. It returns a Promise that resolves with the instance upon completion or rejects with any errors during the boot process. Options can be provided to customize the boot-time behavior. ```APIDOC ## visit (url, options) ### Description Boots a new instance of `ApplicationInstance` for the current application and navigates it to the given `url`. Returns a `Promise` that resolves with the instance when the initial routing and rendering is complete, or rejects with any error that occurred during the boot process. When `autoboot` is disabled, calling `visit` would first cause the application to boot, which runs the application initializers. This method also takes a hash of boot-time configuration options for customizing the instance's behavior. ### Method `visit(url, options)` ### Endpoint N/A (This is a method call on an Application instance) ### Parameters * **url** (String) - The initial URL to navigate to. * **options** (Object) - ApplicationInstance.BootOptions - A hash of boot-time configuration options. ### Request Body Refer to `ApplicationInstance.BootOptions` for available fields. Example: ```json { "location": "none", "rootElement": "#container" } ``` ### Request Example ```javascript MyApp.visit("/", { location: "none", rootElement: "#container" }); ``` ### Response * **Promise** - A Promise that resolves with the application instance or rejects with an error. ### Response Example ```javascript // Example of resolving promise App.visit('/demo', options).then((instance) => { console.log('App booted successfully:', instance); }).catch((error) => { console.error('App boot failed:', error); }); ``` ### Error Handling Rejects the promise with any error encountered during the boot process. ``` -------------------------------- ### Ember.Service Import Example Source: https://api.emberjs.com/ember/6.7/classes/service Demonstrates how to import the Service class from the '@ember/service' module in an Ember.js application. ```javascript import Service from '@ember/service'; ``` -------------------------------- ### Ember.js: Get Multiple Property Values Source: https://api.emberjs.com/ember/release/classes/Route Retrieves the values of multiple properties from an Ember object simultaneously. Accepts a list of property names as separate arguments or as an array. ```javascript // Using separate arguments: record.getProperties('firstName', 'lastName', 'zipCode'); // { firstName: 'John', lastName: 'Doe', zipCode: '10011' } // Using an array: record.getProperties(['firstName', 'lastName', 'zipCode']); // { firstName: 'John', lastName: 'Doe', zipCode: '10011' } ``` -------------------------------- ### Application Visit API Source: https://api.emberjs.com/ember/release/classes/Application Boots a new instance of `ApplicationInstance` for the current application and navigates it to the given URL. ```APIDOC ## visit (url, options) ### Description Boots a new instance of `ApplicationInstance` for the current application and navigates it to the given `url`. Returns a `Promise` that resolves with the instance when the initial routing and rendering is complete, or rejects with any error that occurred during the boot process. ### Method `visit(url, options)` ### Parameters #### Path Parameters - **url** (String) - Required - The initial URL to navigate to. #### Query Parameters - **options** (Object) - Optional - A hash of boot-time configuration options for customizing the instance's behavior. See the documentation on `ApplicationInstance.BootOptions` for details. ### Request Example ```javascript MyApp.visit("/", { location: "none", rootElement: "#container" }); ``` ### Response #### Success Response (Promise) - **Promise** - A promise that resolves with the `ApplicationInstance` when the initial routing and rendering is complete. #### Response Example ```javascript MyApp.visit("/demo", options).then(function(instance) { // App has booted and rendered }); ``` ``` -------------------------------- ### init Source: https://api.emberjs.com/ember/6.7/classes/emberobject An overridable method called when objects are instantiated. It is typically used for setup tasks. ```APIDOC ## init ### Description An overridable method called when objects are instantiated. By default, it does nothing unless overridden. It is crucial to call `this._super(...arguments)` if overriding `init` in framework classes like `Component`. ### Method `init()` ### Example ```javascript import EmberObject from '@ember/object'; const Person = EmberObject.extend({ init() { alert(`Name is ${this.get('name')}`); } }); let steve = Person.create({ name: 'Steve' }); // alerts 'Name is Steve'. ``` ### Note If overriding `init` for framework classes, ensure `this._super(...arguments)` is called to allow Ember's setup work. ``` -------------------------------- ### boot Method Source: https://api.emberjs.com/ember/6.7/classes/engineinstance Initializes the EngineInstance and returns a promise that resolves when the boot process is complete. ```APIDOC ## boot(options) ### Description Initialize the `EngineInstance` and return a promise that resolves with the instance itself when the boot process is complete. The primary task here is to run any registered instance initializers. ### Method `boot` ### Endpoint N/A (This is a method call on an instance) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript instance.boot(options); ``` ### Response #### Success Response (200) * **Promise** - A promise that resolves with the instance itself or rejects with an error. #### Response Example ```json // Example of a resolved promise value: { "__ember_instance__": true, // ... other instance properties } ``` ``` -------------------------------- ### Namespace Class Overview Source: https://api.emberjs.com/ember/6.7/classes/Namespace Provides an overview of the Ember.js Namespace class, its purpose, and how it extends EmberObject. Includes an example of creating a new namespace. ```APIDOC ## Class Namespace public ### Description A Namespace is an object usually used to contain other objects or methods such as an application or framework. Create a namespace anytime you want to define one of these new containers. ### Extends EmberObject ### Example Usage ```javascript MyFramework = Ember.Namespace.create({ VERSION: '1.0.0' }); ``` ``` -------------------------------- ### Ember.js notifyPropertyChange Example Source: https://api.emberjs.com/ember/6.7/classes/NoneLocation Demonstrates the use of `notifyPropertyChange` in Ember.js to manually trigger observer notifications for a property. This is useful when a property's value is changed without using `get()` or `set()`. ```javascript this.notifyPropertyChange('someProperty'); ``` -------------------------------- ### POST /object/init Source: https://api.emberjs.com/ember/release/classes/NoneLocation Initializes a new object instance. This method can be overridden to perform custom setup logic during object creation. ```APIDOC ## POST /object/init ### Description An overridable method called when objects are instantiated. By default, it does nothing unless overridden during class definition. Remember to call `this._super(...arguments)` if you override `init` in framework classes. ### Method POST ### Endpoint `/object/init` ### Parameters None ### Request Example ```json { "example": "" } ``` ### Response #### Success Response (200) - **status** (String) - Indicates successful initialization. #### Response Example ```json { "example": "status: 'initialized'" } ``` ``` -------------------------------- ### Ember.js Get Multiple Properties Example Source: https://api.emberjs.com/ember/6.7/classes/DataAdapter Shows how to retrieve multiple property values from an Ember object using the `getProperties` method. It accepts a list of property names as arguments or an array. ```javascript record.getProperties('firstName', 'lastName', 'zipCode'); // { firstName: 'John', lastName: 'Doe', zipCode: '10011' } record.getProperties(['firstName', 'lastName', 'zipCode']); // { firstName: 'John', lastName: 'Doe', zipCode: '10011' } ``` -------------------------------- ### boot Method Source: https://api.emberjs.com/ember/6.7/classes/applicationinstance Initializes the EngineInstance and returns a promise that resolves when the boot process is complete. ```APIDOC ## Method: boot ### Description Initialize the `EngineInstance` and return a promise that resolves with the instance itself when the boot process is complete. The primary task here is to run any registered instance initializers. ### Method `boot(options)` ### Parameters #### Query Parameters * **options** (Object) - Options for the boot process. See `BootOptions` documentation for details. ### Returns Promise - A promise that resolves with the instance itself when the boot process is complete. ``` -------------------------------- ### Application Visit API Source: https://api.emberjs.com/ember/6.7/classes/application The `visit` method boots a new instance of `ApplicationInstance` for the current application and navigates it to a specified URL. It returns a Promise that resolves with the instance upon completion or rejects with an error. ```APIDOC ## visit (url, options) ### Description Boots a new instance of `ApplicationInstance` for the current application and navigates it to the given `url`. This method returns a `Promise` that resolves with the instance when the initial routing and rendering is complete, or rejects with any error that occurred during the boot process. It can be used with `autoboot` disabled for custom initialization and rendering scenarios. ### Method `visit(url, options)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters Details - **url** (String) - The initial URL to navigate to. - **options** (Object) - An object containing boot-time configuration options for customizing the instance's behavior. Refer to `ApplicationInstance.BootOptions` for available options. ### Request Example ```javascript MyApp.visit("/", { location: "none", rootElement: "#container" }); ``` ### Response #### Success Response (Promise) - **ApplicationInstance** - The booted application instance. - **Error** - An error that occurred during the boot process. #### Response Example ```javascript App.visit('/demo', options).then((instance) => { // App has booted and navigated to /demo }); ``` ``` -------------------------------- ### Ember.js: Get Property Value Source: https://api.emberjs.com/ember/release/classes/Route Retrieves the value of a property from an Ember object. It supports standard properties, computed properties, and the unknownProperty handler, unifying property access syntax. ```javascript import { computed } from '@ember/object'; fullName: computed('firstName', 'lastName', function() { return this.get('firstName') + ' ' + this.get('lastName'); }) // Usage example: // let value = object.get('propertyName'); ``` -------------------------------- ### Transition Methods Source: https://api.emberjs.com/ember/6.7/classes/Transition Provides documentation for the methods available on the Transition object. ```APIDOC ## Methods ### abort : Transition #### Description Aborts the `Transition`. Note you can also implicitly abort a transition by initiating another transition while a previous one is underway. #### Method `abort()` #### Returns `Transition` - This transition ### catch (onRejection, label) : Promise #### Description Forwards to the internal `promise` property which you can use in situations where you want to pass around a thennable, but not the `Transition` itself. #### Method `catch(onRejection: Function, label?: String): Promise` #### Parameters * `onRejection` (Function) - The function to call if the promise is rejected. * `label` (String, optional) - An optional string for labeling the promise, useful for tooling. #### Returns `Promise` ### debugAbortStack : string #### Description In non-production builds, this function will return the stack that this `Transition` was aborted within (or `undefined` if the `Transition` has not been aborted yet). In production builds, this function will not be present. #### Method `debugAbortStack()` #### Returns `string` ### debugCreationStack : string #### Description In non-production builds, this function will return the stack that this `Transition` was created within. In production builds, this function will not be present. #### Method `debugCreationStack()` #### Returns `string` ### finally (callback, label) : Promise #### Description Forwards to the internal `promise` property which you can use in situations where you want to pass around a thennable, but not the `Transition` itself. #### Method `finally(callback: Function, label?: String): Promise` #### Parameters * `callback` (Function) - The function to call when the promise is settled. * `label` (String, optional) - An optional string for labeling the promise, useful for tooling. #### Returns `Promise` ### followRedirects : Promise #### Description Transitions are aborted and their promises rejected when redirects occur; this method returns a promise that will follow any redirects that occur and fulfill with the value fulfilled by any redirecting transitions that occur. #### Method `followRedirects(): Promise` #### Returns `Promise` - A promise that fulfills with the same value that the final redirecting transition fulfills with. ### method (method) : Transition #### Description Sets the URL-changing method to be employed at the end of a successful transition. By default, a new `Transition` will just use `updateURL`, but passing 'replace' to this method will cause the URL to update using 'replaceWith' instead. Omitting a parameter will disable the URL change, allowing for transitions that don't update the URL at completion. #### Method `method(method: String): Transition` #### Parameters * `method` (String) - The type of URL-changing method to use. Accepted values are 'replace', falsy values, or any other non-falsy value (interpreted as an updateURL transition). #### Returns `Transition` - This transition ### retry : Transition #### Description Retries a previously-aborted transition (making sure to abort the transition if it's still active). Returns a new transition that represents the new attempt to transition. #### Method `retry(): Transition` #### Returns `Transition` - A new transition ### then (onFulfilled, onRejected, label) : Promise #### Description A standard promise hook that resolves if the `Transition` succeeds and rejects if it fails/redirects/aborts. Forwards to the internal `promise` property which you can use in situations where you want to pass around a thennable, but not the `Transition` itself. #### Method `then(onFulfilled?: Function, onRejected?: Function, label?: String): Promise` #### Parameters * `onFulfilled` (Function, optional) - The function to call when the promise is fulfilled. * `onRejected` (Function, optional) - The function to call when the promise is rejected. * `label` (String, optional) - An optional string for labeling the promise, useful for tooling. #### Returns `Promise` ``` -------------------------------- ### Ember.js: Setting templateName for a Route Source: https://api.emberjs.com/ember/release/classes/Route Shows how to specify a custom template name for an Ember.js Route using the `templateName` property. This example demonstrates setting a specific template for a list route and how other routes can extend it. ```javascript import Route from '@ember/routing/route'; export default class PostsListRoute extends Route { templateName = 'posts/list'; } ``` ```javascript import PostsListRoute from '../posts/list'; export default class PostsIndexRoute extends PostsListRoute {}; ``` ```javascript import PostsListRoute from '../posts/list'; export default class PostsArchivedRoute extends PostsListRoute {}; ``` -------------------------------- ### Ember.js Browser Application Manual Boot Example Source: https://api.emberjs.com/ember/6.7/classes/Application Demonstrates manual booting of an Ember application instance in a browser environment, disabling autoboot. This is useful for embedding Ember apps into existing pages or for creating specialized demos, allowing control over rendering location and URL updates. ```javascript import MyApp from 'my-app'; $(function() { let App = MyApp.create({ autoboot: false }); let options = { // Override the router's location adapter to prevent it from updating // the URL in the address bar location: 'none', // Override the default `rootElement` on the app to render into a // specific `div` on the page rootElement: '#demo' }; // Start the app at the special demo URL App.visit('/demo', options); }); ``` ```javascript import MyApp from 'my-app'; $(function() { let App = MyApp.create({ autoboot: false }); let sessionId = MyApp.generateSessionID(); let player1 = App.visit(`/matches/join?name=Player+1&session=${sessionId}`, { rootElement: '#left', location: 'none' }); let player2 = App.visit(`/matches/join?name=Player+2&session=${sessionId}`, { rootElement: '#right', location: 'none' }); Promise.all([player1, player2]).then(() => { // Both apps have completed the initial render $('#loading').fadeOut(); }); }); ``` -------------------------------- ### Sending Actions in Ember Route (JavaScript) Source: https://api.emberjs.com/ember/release/classes/Route The `send` method in Ember.js routes sends an action to the router, which then delegates it to the active route hierarchy. This is demonstrated with an example of tracking clicks using the `@action` decorator. ```javascript import Route from '@ember/routing/route'; import { action } from '@ember/object'; export default class ApplicationRoute extends Route { @action track(arg) { console.log(arg, 'was clicked'); } } // Example of sending an action from another route: import Route from '@ember/routing/route'; import { action } from '@ember/object'; export default class IndexRoute extends Route { @action trackIfDebug(arg) { if (debug) { this.send('track', arg); } } } ``` -------------------------------- ### EngineInstance - boot Source: https://api.emberjs.com/ember/6.7/classes/EngineInstance Initializes the EngineInstance and returns a promise that resolves when the boot process is complete, primarily running instance initializers. ```APIDOC ## POST /websites/api_emberjs (boot) ### Description Initializes the `EngineInstance` and returns a promise that resolves with the instance itself when the boot process is complete. The primary task here is to run any registered instance initializers. ### Method POST ### Endpoint /websites/api_emberjs ### Parameters #### Query Parameters - **options** (Object) - Optional - Boot options for the engine instance. ### Request Body ```json { "options": { "someOption": "value" } } ``` ### Response #### Success Response (200) - **EngineInstance** (Promise) - A promise that resolves with the initialized engine instance. #### Response Example ```json { "message": "Engine instance booting..." } ``` ``` -------------------------------- ### Handling Route Transitions with Ember.js Actions Source: https://api.emberjs.com/ember/release/classes/Route Demonstrates how to use the `willTransition` action within an Ember.js Route to intercept navigation. This example shows how to check for unsaved data and prompt the user before allowing the transition to proceed. ```javascript import Route from '@ember/routing/route'; import { action } from '@ember/object'; export default class FormRoute extends Route { @action willTransition(transition) { // Check if user has entered data and if they want to abandon progress if (this.controller.get('userHasEnteredData') && !confirm('Are you sure you want to abandon progress?')) { // Abort the transition if the user chooses not to abandon transition.abort(); } else { // Allow the transition to proceed or be handled by parent routes return true; } } } ``` -------------------------------- ### Ember.js Multiple Instances with Visit Source: https://api.emberjs.com/ember/6.7/classes/application Demonstrates booting multiple isolated Ember.js application instances on the same page for features like split-screen multiplayer experiences. Each instance is configured with unique root elements and options. ```javascript import MyApp from 'my-app'; $(function() { let App = MyApp.create({ autoboot: false }); let sessionId = MyApp.generateSessionID(); let player1 = App.visit(`/matches/join?name=Player+1&session=${sessionId}`, { rootElement: '#left', location: 'none' }); let player2 = App.visit(`/matches/join?name=Player+2&session=${sessionId}`, { rootElement: '#right', location: 'none' }); Promise.all([player1, player2]).then(() => { // Both apps have completed the initial render $('#loading').fadeOut(); }); }); ``` -------------------------------- ### Customizing ApplicationInstance Boot Options with JavaScript Source: https://api.emberjs.com/ember/6.7/classes/ApplicationInstance Demonstrates how to pass boot-time configuration options to MyApp.visit. It shows how to specify 'location' and 'rootElement' for customizing the application instance's behavior during boot. Note that not all combinations of options are valid. ```javascript MyApp.visit("/", { location: "none", rootElement: "#container" }); ``` -------------------------------- ### Independent Array Property via Computed Property Source: https://api.emberjs.com/ember/6.7/classes/Mixin This Ember.js mixin example demonstrates how to ensure each object implementing the mixin gets its own independent array property. This is achieved by defining the `filters` property as a computed property that returns a new array instance. ```typescript import Mixin from '@ember/object/mixin'; import { A } from '@ember/array'; import { computed } from '@ember/object'; // filters will be a separate array for every object implementing the mixin const FilterableMixin = Mixin.create({ filters: computed(function() { return A(); }) }); ``` -------------------------------- ### Get Route Parameters with 'paramsFor' in Ember.js Source: https://api.emberjs.com/ember/release/classes/Route The 'paramsFor' method retrieves a hash containing the parameters of an ancestor route. This is particularly useful in child routes to access parameters defined in parent routes, such as dynamic segments in the route path. ```javascript import Route from '@ember/routing/route'; export default class MemberInterestRoute extends Route { model() { return this.paramsFor('member'); } } ``` -------------------------------- ### Property Change Notification Source: https://api.emberjs.com/ember/release/classes/Route The `notifyPropertyChange` method is used to inform Ember's observer system that a property's value may have changed, even if `get()` or `set()` were not explicitly used. This is a convenience method that calls `propertyWillChange` and `propertyDidChange`. ```APIDOC ## POST /users/{userId}/preferences ### Description Updates user preferences and notifies observers of potential changes. ### Method POST ### Endpoint `/users/{userId}/preferences` ### Parameters #### Path Parameters - **userId** (String) - Required - The ID of the user whose preferences are being updated. #### Query Parameters None #### Request Body - **theme** (String) - Optional - The preferred theme for the user. - **notifications** (Boolean) - Optional - Whether to enable notifications. ### Request Example ```json { "theme": "dark", "notifications": true } ``` ### Response #### Success Response (200) - **message** (String) - A confirmation message indicating the preferences were updated. #### Response Example ```json { "message": "User preferences updated successfully." } ``` ``` -------------------------------- ### Subscribe Once to Events with 'one' in Ember.js Source: https://api.emberjs.com/ember/release/classes/Route The 'one' method is similar to 'on' but cancels the subscription after the event is triggered for the first time. This is ideal for actions that should only occur once, such as initial setup or one-time notifications. An optional target can be provided to set the 'this' context. ```javascript // Example usage of 'one' (specific code not provided in text, conceptual) ``` -------------------------------- ### Custom Location Implementation Example Source: https://api.emberjs.com/ember/6.7/classes/Location Demonstrates how to create a custom location implementation that extends Ember's routing capabilities. ```APIDOC ## Custom Location Implementation ### Description Allows developers to create their own location management strategies by extending the `Location` API. Ember automatically discovers custom implementations located in `app/locations/*`. ### Example ```javascript import HistoryLocation from '@ember/routing/history-location'; export default class MyHistory { implementation = 'my-custom-history'; constructor() { this._history = HistoryLocation.create(...arguments); } create() { return new this(...arguments); } pushState(path) { this._history.pushState(path); } // Implement other required Location API methods as needed getURL() { return this._history.getURL(); } setURL(path) { this._history.setURL(path); } replaceURL(path) { this._history.replaceURL(path); } onUpdateURL(callback) { this._history.onUpdateURL(callback); } formatURL(url) { return this._history.formatURL(url); } } ``` ### Usage Pass the name of your custom implementation (e.g., `'my-custom-history'`) to configure Ember to use it. ``` -------------------------------- ### Notify Property Change with Ember.js Source: https://api.emberjs.com/ember/release/classes/Route Explains the `notifyPropertyChange` method in Ember.js, inherited from `Observable`. This method is used to manually trigger the observer system, notifying listeners that a property's value may have changed, even if `get()` or `set()` were not directly used. ```javascript notifyPropertyChange(keyName) : Observable ``` -------------------------------- ### Initialize Ember.js Object with `init` Source: https://api.emberjs.com/ember/6.7/classes/EmberObject Overrides the `init` method to perform custom setup logic when an Ember object is instantiated. It's crucial to call `this._super(...arguments)` if overriding `init` for framework classes to ensure proper initialization. Example shows accessing a property ('name') during initialization. ```javascript import EmberObject from '@ember/object'; const Person = EmberObject.extend({ init() { alert(`Name is ${this.get('name')}`); } }); let steve = Person.create({ name: 'Steve' }); ``` -------------------------------- ### Manual Property Change Notification in Ember.js Source: https://api.emberjs.com/ember/6.7/classes/route Provides an example of using 'notifyPropertyChange' in Ember.js to manually trigger observer notifications for a property. This method is useful when a property's value is modified without using Ember's `get` or `set` methods, ensuring that observers are still alerted to potential changes. ```javascript notifyPropertyChange(keyName) { // ... implementation details ... return this; } ``` -------------------------------- ### Basic Promise Usage (JavaScript) Source: https://api.emberjs.com/ember/6.7/classes/Promise Demonstrates the fundamental creation and consumption of a Promise. It shows how to instantiate a Promise with resolve/reject callbacks and how to attach fulfillment and rejection handlers using the `then` method. ```javascript let promise = new Promise(function(resolve, reject) { // on success resolve(value); // on failure reject(reason); }); promise.then(function(value) { // on fulfillment }, function(reason) { // on rejection }); ```