Posts

Showing posts from December, 2017

Binding - Computed Properties

- Sometimes it is desirable to return a dynamically computed value when accessing a property, or you may want to reflect the status of an internal variable without requiring the use of explicit method calls. - In JavaScript, this can be accomplished with the use of a getter. - Here's an example Person class that exposes a fullName property that computes it's value using the firstName and lastName properties. export class Person {            firstName = 'Pradnya';            lastName = 'Kulkarni Telang';            get fullName() {                  return `${this.firstName} ${this.lastName}`;           } } - The binding system will examine the property's descriptor , determine that the value of the prope...

Binding - Delegate vs Trigger

- Use delegate except when you cannot use delegate.  - Event delegation is a technique used to improve application performance.  - It drastically reduces the number of event subscriptions by leveraging the "bubbling" characteristic of most DOM events.  - With event delegation, handlers are not attached to individual elements.  - Instead, a single event handler is attached to a top-level node such as the body element.  - When an event bubbles up to this shared top-level handler the event delegation logic calls the appropriate handler based on the event's target . - To find out if event delegation can be used with a particular event, google mdn [event name] event. - In fact, preceding any web platform related google search with mdn often returns a high quality result from the Mozilla Developer Network.  - Once you're on the event's MDN page, check whether the event  bubbles .  - Only events that bubble can be used with Aurelia's ...

Binding - Selects

Introduction - A <select> element can serve as a single-select or multiple-select "picker" depending on whether the multiple attribute is present.  - The binding system supports both use cases.  - The samples below demonstrate a variety scenarios, all use a common series of steps to configure the select element: - Add a <select> element to the template & decide whether the multiple attribute should be applied. - Bind the select element's value attribute to a property.  - In "multiple" mode, the property should be an array.  - In singular mode it can be any type. - Define the select element's < option > elements.  - You can use the repeat or add each option element manually. - Specify each option's value via the model property: <option model.bind="product.id"></option> - You can use the standard value attribute instead of model , just remember- it will coerce anything it's assigned to a...

Binding - Radios

Introduction - A group of radio inputs is a type of "single select" interface.  - Aurelia supports two-way binding any type of property to a group of radio inputs.  - The examples below illustrate binding number, object, string and boolean properties to sets of radio inputs.  - In each of the examples there's a common set of steps: - Group the radios via the name property. Radio buttons that have the same value for the name attribute are in the same "radio button group"; only one radio button in a group can be selected at a time. Define each radio's value using the model property. Two-way bind each radio's checked attribute to a "selected item" property on the view-model. Numbers - uses a numeric "selected item" property.  - each radio input will be assigned a number value via the model property.  - Selecting a radio will cause it's model value to be assigned to the selectedProductId property. Objects - The ...

Binding - Checkboxes

Introduction Aurelia supports two-way binding a variety of data-types to checkbox input elements. Booleans Bind a boolean property to an input element's checked attribute using checked.bind="myBooleanProperty".  Array of Numbers - A set of checkbox elements is a multiple selection interface. - If you have an array that serves as the "selected items" list, you can bind the array to each input's checked attribute. - The binding system will track the input's checked status, adding the input's value to the array when the input is checked & removing the input's value from the array when the input is unchecked. - To define the input's "value", bind the input's model attribute: model.bind="product.id". Array of Objects - Numbers aren't the only type of value you can store in a "selected items" array.  - The binding system supports all types, including objects. Array of Objects with Match...

Style vs Css attribute

Style   - can bind a css string or object to an element's style attribute.  - Use the style attribute's alias, css when doing string interpolation to ensure your application is compatible with Internet Explorer & Edge. Legal Style Interpolation < template >         < div css = " width: ${width}px; height: ${height}px; " > </ div > </ template > Class - can bind an element's class attribute using string interpolation or with .bind/.one-time .  - Class Binding      <template>            <div class="foo ${isActive ? 'active' : ''} bar"></div>            <div class.bind="isActive ? 'active' : ''"></div>            <div class.one-time="isActive ? 'active' : ''"></div>     ...

Fundamentals - Cheat Sheet VII

The Event Aggregator - If you include the aurelia-event-aggregator plugin using "basicConfiguration" or "standardConfiguration" then the singleton EventAggregator's API will be also present on the Aurelia object.  - You can also create additional instances of the EventAggregator, if needed, and "merge" them into any object. To do this, import includeEventsIn and invoke it with the object you wish to turn into an event aggregator.  - For example includeEventsIn(myObject). Now my object has publish and subscribe methods and can be used in the same way as the global event aggregator, detailed below. Publishing on a Channel   import { inject } from 'aurelia-framework' ;   import { EventAggregator } from 'aurelia-event-aggregator' ;   @ inject ( EventAggregator )   export class APublisher {              constructor ( eventAggregator ) {       ...

Fundamentals - Cheat Sheet VI

Custom Elements Custom Element View-Model Declaration import { customElement , bindable } from 'aurelia-framework' ;   @ customElement ( 'say-hello' )   export class SayHello {              @bindable to ;                          speak ( ) {                       alert ( `Hello ${ this . to } !` ) ;              } } Custom Element View Declaration < template >           < button click.trigger = " speak() " > Say Hello To ${to} </ button >   </ template > Custom Element Use < template >       ...

Fundamentals - Cheat Sheet V

Custom Attributes Simple Attribute Declaration import { inject , customAttribute , DOM } from 'aurelia-framework' ;   @ customAttribute ( 'my-attribute' )   @ inject ( DOM . Element )   export class Show {              constructor ( element ) {                                 this . element = element ;              }              valueChanged ( newValue , oldValue ) {                      ...              } } Simple Attribute Use < template >        ...