Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

5 Benefits Of Choosing Aurelia Over AngularJS

DZone's Guide to

5 Benefits Of Choosing Aurelia Over AngularJS

In this post, we are going to discuss the specific benefits of Aurelia and how it overtakes other popular frameworks in many cases.

· Web Dev Zone
Free Resource

Prove impact and reduce risk when rolling out new features. Optimizely Full Stack helps you experiment in any application.

Angular is the most popular JavaScript framework by far and React is a very impactful library that we use for many reasons. However, other than these two, there are a few other good frameworks that have come to our attention recently, including Aurelia and Vue.js.

In our last blog post, we had a comparative discussion between Vue.js, Angularjs, and Reactjs. In this post, we are going to discuss the specific benefits of Aurelia and how it overtakes other popular frameworks in many cases.

Further reading: AngularJS vs ReactJS : What’s good for your business?

A Brief Introduction to Aurelia

aurelia js -logo

While Google was working on Angular 2.0 update, another framework called Aurelia emerged. It is a product from Durandal Inc. and being advertised as “the next generation UI Framework” and “the most advanced and developer friendly front-end framework today”. It has few specific features that our team at ValueCoders found interesting and useful to our project works. Let's start with Routing Composition:

Routing & UI Composition

The advanced client-side router with the  dynamic route patterns, child routers, pluggable pipeline, and asynchronous screen activation. In fact, you can do dynamic, data-driven UI composition without a router.

Also, through a router-view like component, any number of routes can be handled. Here's an example:

“app.html”:
<div>
    <router-view></router-view>
</div>
“app.js”:
export class App {
    configureRouter(config, router) {
        title = 'Title for App';
        config.map([
            { route: ['/routeName/'],
             name: 'FileNameToRun',
             moduleId: 'PathOfFileToRun',
             nav: true, title:'Title for Route' }
        ]);
        this.router = router;
    }
}

These features are also there in Angular. However, Angular was ideally built as a monolithic framework. All of its components, including Router, were wrapped into one large bundle. This monolithic architecture made it difficult to remove components and change them when necessary.

Aurelia, on the other hand, takes a more modern approach. While it’s a full framework, it is composed of a collection of libraries that work together using well-defined interfaces so that it’s completely modular. This means that a web app only needs to include the dependencies that it needs not the complete bundle. Hence, it means that as long as implementations adhere to the defined interface, individual components can be swapped or changed with minimal confusion.

MV* Approach

Aurelia follows a model-view approach like nobody else. In Aurelia,  there is no need to specify the particular controllers of view-models, as the naming convention does that part. Here is a simple example:

“AnyFile.html”:  Any file loaded under router-view or called at the time of instantiating Aurelia App.
<template>
    <!-- HTML(View) and Aurelia(Model) code goes here -->
</template>
“AnyFile.js”: Controller of the Anyfile.html view-model.
    export class AnyFile {
        constructor() {

    }
}

While comparing with Angular, there are differences in the MV* components. More precisely, the digest cycle of Angular is different from Aurelia. A big disadvantage of Angular JS, at least in v1, is that it has a very sheer learning curve. You will have to know its internals, the complete digest cycle pretty well and have to know the effect on performance while using filters and $watch expressions. Whereas, Aurelia is simple and learning curve is quite smooth.

Language Support

Aurelia's APIs are carefully designed to be consumed naturally by both today's and tomorrow's most useful web programming languages. Aurelia supports ES5, ES2015, ES2016 and Typescript which is very helpful and gives you high flexibility.

Further, writing web applications using ES6 is not a new thing. In fact, there are many solutions out there that can allow you to write Angular apps using ES6. However, Aurelia takes it a step further by providing support for ES6 as well as  Gulpfiles with customized build system for transpiring your ES6 down to ES5 compatible code.

Extensible HTML

Aurelia's extensible HTML compiler lets you create custom HTML elements. It helps you add custom attributes to existing elements and control template generation, all with full support for data-binding, dynamic loading,  and high-performance batched  rendering. Here's an example to help you out:

“AnyParentFile.html”:
<template>
    <div custom-attribute></div>
    <!-- Custom Element -->
    <child-element></child-element>
</template>
“ChildElement.html”: View Model for custom element
<template>
    <!-- Child element view model code goes here -->
</template>
“AnyParentFile.js”: Controller for AnyParentFile
export class AnyParentFile {
    constructor() {

    }
}
“ChildElement.js”: Controller for ChildElement
// Module customElement
import { customElement } from 'aurelia-framework';
// create custom element childElement
@customElement('childElement')
export class ChildElement {
    constructor() {

    }
}

When AngularJS was developed, the standards for extending HTML was not matured. That's why AngularJS created proprietary solutions for templating and custom elements.

Today, the Web Component spec defines a set of rules for both custom elements & templating. Aurelia actively adheres to these standards, supporting the HTML imports, <template> element, Shadow DOM, and native custom elements making it more advanced than Angular.

Data-Binding

Aurelia supports two types of data-binding:

  1. One-way Data-Binding
  2. Two-way Data-Binding

By using adaptive techniques you can select the most efficient way to observe each property in your model and automatically synchronize your UI with best-in-class performance. Here is an example-

Two-way Data-Binding

<!-- these have the same result -->
<input value.bind="anyValue & twoWay>
<input value.two-way="anyValue">

One-Way Data-Binding:

<!-- these have the same result -->
<input value.bind="anyValue & oneWay>
<input value.one-way="anyValue">

Angular also allows two-way data binding, however, for new developers it's not that easy to adopt the Angular way. Secondly, with a high number of filters, watches, a complex DOM structure and so on, you will find performance issues. Although some improvements are implemented later on, yet they are not much effective.

On the other side, as Aurelia is less complex and not difficult to learn, there are not much chances to performance issues to implement two-way data binding.

Bottom Line:

Right now you must be using a popular framework like Angular or React. However, you might face difficulty when you step outside the Golden Path. On the other hand, Aurelia.io is built as a set of micro modules, which makes it quite flexible.

Aurelia prides itself on making almost no assumption and just a minimal set of conventions for ease of use which are very easy to reconfigure or override. Hence, it depends on the project requirement and personal choice when you choose a framework. If you like a less constrained framework with more freedom then Aurelia is for you.

This article was originally published on ValueCoders.

With SDKs for all major client and server side platforms, you can experiment on any platform with Optimizely Full Stack.

Topics:
angular ,aurelia ,react

Published at DZone with permission of Arnab Sarkar, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}