Posts

Fundamentals - Cheat Sheet IV

Routing Basic Route Configuration export class App {              configureRouter ( config , router ) {                             this . router = router ;                             config . title = 'Aurelia' ;                             config . map ( [                                        { route : [ '' , 'home' ] , name : 'home' , moduleId : 'home/index' } ,...

Fundamentals - Cheat Sheet III

Templating View Resources Conditionally displays ah HTML element < template >          < div show.bind = " isSaving " class = " spinner " > </ div > </ template > Conditionally add/remove an HTML element < template >          < div if.bind = " isSaving " class = " spinner " > </ div > </ template > Conditionally add/remove a group of elements < template >          < input value.bind = " firstName " >         < template if.bind = " hasErrors " > < i class = " icon error " > </ i >                          ${errorMessage}         </ template > </ template ...

Fundamentals - Cheat Sheet II

Templating Basics: Requiring Resources <template>         <require from='nav-bar'></require>            <nav-bar router.bind="router"></nav-bar>         <div class="page-host">                  <router-view></router-view>        </div> </template> When the browser loads in the template it very helpfully validates the structure of the HTML, notices that you have an invalid tag inside your table definition, and very unhelpfully removes it for you before Aurelia even has a chance to examine your template. as-element  attribute ensures a valid HTML table structure at load time Compose an existing object instance with a view <template>         <table>                <tr repeat.for="r...

Fundamentals - Cheat Sheet

Configuration & Startup: Bootstrapping Older Browsers <script src="jspm_packages/system.js"></script> <script src="config.js"></script> <script>            SystemJS.import('aurelia-polyfills').then(function() {                            return SystemJS.import('webcomponents/webcomponentsjs/MutationObserver');            }).then(function() {                        SystemJS.import('aurelia-bootstrapper');            }); </script> Creating Components: Explicit Configuration import {useView} from 'aurelia-framework'; @useView('./hello.html') export class Hello {             ... } Dependency Injection: Declaring Dependencies import {inject} from 'aurelia-fra...

Fundamentals - Securing App

Authentication and Authorization: - You can improve the user-experience by plugging into Aurelia's router pipeline with your security specifics. Here's a quick example of how you might use Aurelia's router to disallow client-side routes based on user role import {Redirect} from 'aurelia-router'; export class App {            configureRouter(config) {                    config.title = 'Aurelia';                    config.addPipelineStep('authorize', AuthorizeStep);                    config.map([                               { route: ['welcome'], moduleId: 'welcome', title: 'Welcome', settings: { roles: [] } },                             ...

Fundamentals - Dependency Injection V

Resolvers: - The DI container uses Resolvers internally to provide all instances.  - When explicitly configuring the container, you are actually specifying what Resolver should be associated with a particular lookup key. However, there's a second way that resolvers are useful. Instead of supplying a key as part of the inject decorator, you can provide a Resolver instead. This resolver then communicates with the container to provide special resolution behavior, specific to the injection. Lazy - Injects a function for lazily evaluating the dependency.         ex. Lazy.of(HttpClient) All - Injects an array of all services registered with the provided key.         ex. All.of(Plugin) Optional - Injects an instance of a class only if it already exists in the container; null otherwise.         ex. Optional.of(LoggedInUser) Parent - Skips starting dependency resolution from the current container and instead ...

Fundamentals - Dependency Injection IV

Explicit Configuration: - You may desire to change the behavior of individual classes for the specific needs of application. This is easy to do by either directly using the Container API or by decorating class with a Registration The Container Registration API: The usual way to configure a class's lifetime is to use the Container API directly. Typically, you will want to do this configuration up-front in your application's main configure method. The Aurelia  instance that is provided during configuration has a container  property which points to the root DI container for your application. Recall that any Resolver configured at the application root will apply unless a child container has explicitly overridden the behavior. container.registerSingleton(key: any, fn?: Function): void - This method allows you to register a class as a singleton. This is the default, so there's rarely a reason to call this method. It is provided in the API for completeness. When callin...