AngularJS 2.0 Status and Preview

Created: 2015-03-25 22:29 Updated: 2015-03-25 22:29 Source: http://ng-learn.org/2014/03/AngularJS-2-Status-Preview/ Notebook: All Tech/Frontend Development

Mar
19
AngularJS 2.0 Status and Preview

AngularJS team has been busy working on AngularJS 2.0. As we mentioned before, this is not a complex major update; this is a whole rewrite! Having learnt many lessons from AngularJS and AngularDart a lot of thinking is being done to produce the future core and its ecosystem. We will walk you through what you need to know to stay up to date.

Table of Contents

What is AngularJS 2.0 all about?

The team has opted to document each module into an architecture design document. These documents have been available to the community since the beginning. This is turned into warly feedback for the team and a rare and excellent opportunity for the community to participate and better understand a framework from its roots.

Just when I was about to publish this article Brad Green (AngularJS manager) published an article on angularjs blog providing insight on what was being done and which goals were in mind. Great minds think alike? He is tall, blonde, brilliant and work at google surrounded by master minds. Im….not.

Brad does an excellent job expressing the key areas the team is working on. These are the main concepts I gathered: Mobile First, Loosely Couple Modules, Simplicity, Metadata and Performance. If you haven’t already you should read the blog.

I will briefly review these cross cutting subjects and then I will try to summarize all different efforts the team has queued for AngularJS 2.0.

  • ** Mobile First: ** At the ng-conf the team expressed they would go for mobile but I guess we never thought that would mean focus all efforts to get mobile right and then work up to desktops. I think this is a bold and brilliant approach. For the last 3 years this has been the recommended approach we have either received or given when building an application that needs to live in mobile and desktop platforms. If you do it right on mobile, if you tackle loading times, performance and other mobile challenges first, then desktop becomes a much easier task.

  • ** Loosely Couple Modules: ** This one comes without surprises. Angular Team has been deattaching modules from its core for several versions now.

    At the same time, the community started to offer some very interesting modules such as ui router and restangular which have worked as options for some core angular modules.

    Both the angular team and the community have succesfully built a module ecosystem that keeps growing. www.ngmodules.org holds a list of 529 modules. Im sure this does not represent half of the ones that exist out there. As a community we need to better publicize this index.

    In addition, smaller libraries or modules combined with lazy loading generates a boost on performance.

  • ** Simplicity / MetaData: ** One of the goals for Angular 2.0 is allow developers to concentrate on the lines of code related to their business domain. The next version will better hide angular frame. Annotations and ES6 provides the tools and standards to make this possible.

    The team has also embraced feedback coming from a community who found directives syntax to have a rather long learning curve. A much simple dsl for directives is on the works.

What are the challenges?

Change Detection, Dependency Injection, Templating, Persistance, Routing, Logging, Annotations, Documentation, Benchmarking, Touch/Animations, Package Repository, Reference App, Scaffolding and Build/Deploy.

These are the many facets the team is working on. Almost every topic deserves a project of its own.

Some of the design documents have already received enough feedback for the team to produce a first prototype/working version.

These are all moving targets and each deserve its own post to understand how each will work. Here is a brief intro to each subject.

Change Detection

The long term approach is to take advantage of Object.observe() implementation that comes available in browsers such as Chrome 35M. We are currently in 33M.

Object.observe() is a low-level API that lets you add a listener to be notified when a JavaScript object changes state.

If you want to know more about this pattern, follow this link and this link.

While we wait to the browser native change detection, the team has found a solution that is fast and more efficient than the current one available in AngularJS 1.2.

Watchtower.js is super-fast change detection library. This is a javascript port of an already implemented algorithm in AngularDart.

"Internally the change detection algorithm keeps track of fields to check as Record data structure. When reporting changes it returns a list of Records which have changes."

The design document goes over the change detection approach utilized for field, array and map.

If you would like to look at the source code, follow this link: watchtower.js

In future posts we will analyze this in detail. In the meantime, if you would like to read the design document, follow this link: Design Doc

Note: during the ng-conf Brian talked about Zone.js as a candidate for dirty checking. zone.js

Dependency Injection

The design doc is already out-dated but it serves as background history for the current version.

The prototype has grown into a library and it is ready to be tested. Based on ES6 it attempts to provide less complex syntax, declarative annotations and lazy loading.

Take a look at the next code block. This is the Dependency Injection design pattern. All the dependencies are simply passed in as constructor arguments. Heater has no idea where these dependencies (electricity) are coming from. Heater is not coupled to any particular environment. You can re-use it in a different environment, which can be a different configuration of the same project, or a complete different project.

import {Inject} from 'di/annotations';
    import {Electricity} from '../electricity';

    @Inject(Electricity)
    export class Heater {
      constructor(electricity) {
        this.electricity = electricity;
      }

      on() {
        console.log('Turning on the coffee heater...');
      }

      off() {
        console.log('Turning off the coffee heater...');
      }
    }

And here we create a Fake/Mock implementation of the Heater.

import {Provide} from 'di/annotations';
    import {Heater} from './coffee_maker/heater';

    @Provide(Heater)
    export class MockHeater {
      constructor() {}

      on() {
        console.log('Turning on the MOCK heater...');
      }

      off() {}
    }

You may find all the ng-conf videos here: http://ng-conf.ng-learn.org/ Look for dependency injection.

# Clone this repo (or your fork).
        git clone https://github.com/angular/di.js.git

        # Install all the the dev dependencies, such as Karma, Gulp, etc.
        npm install

        # If you wanna use "karma" or "gulp" commands, install also:
        npm install -g karma-cli
        npm install -g gulp

        # Transpile ES6 into ./compiled/*
        gulp build

        # Watch all the sources and transpile on any change
        gulp watch

        gulp build_examples
        gulp serve

If you would like to look at the source code, follow this link: di.js

In future posts we will analyze this in detail. In the meantime, if you would like to read the design document, follow this link: Design Doc

Templating

The goals on this effort are to simplify the directive API, to use web standards, improve performance and provide opportunity to better tooling.

The team has analyzed other available frameworks trying to identify strength and weakness. This roman approach is laid out in the design doc and it is of value for any web developer. There is a special doc for polymer. (link)

The team has a first example using ShadowDom and they are currently working on bindings. Here is an indication on how a very simple directive could look like:

<exp-hello></exp-hello>
@ComponentDirective({
          selector: 'exp-hello',
          template: 'Hello world!'
        })

If you would like to look at the source code, follow this link

And here is candidate usage of one way binding.

{{:foo}}

In future posts we will analyze this in detail. In the meantime, if you would like to read the design document, follow this link

What is ShadowDOM?

Shadow DOM is designed to provide encapsulation by hiding DOM subtrees under shadow roots.
It provides a method of establishing and maintaining functional boundaries between DOM trees and how these trees interact with each other within a document, thus enabling better functional encapsulation within the DOM.

If you would like to understand shadowDom, please follow these links:

If you would like to know more about web components and polymer, follow this link into a brief write-up Addy Osmani does.

You will rapidly notice how much in common Web Components Standards - which includes ShadowDOM - share with AngularJS directives.

Persistance

This is still being documented, commented and reviewed.

There is a lot of thought and consideration being done on storage quotas on different browsers (desktop and mobile), promises, performance, etc.

We will start hearing about rewritten and new modules such as ngHTTP, ngWebSocket, ngStore, ngOffline and ngData.

I believe this topic is going to become a great adventure for this team. There is so much ground to cover and so many performance boundaries.

In future posts we will analyze this in detail. In the meantime, if you would like to read the design document, follow this link

Routing

This is still being documented, commented and reviewed. The team is looking at Ember.js, Durandal (framework built on top of jQuery, Knockout and RequireJS) and Passport (middleware for Express) for reference on other approaches.

The goal is to cover proven requirements such as multiple, nested, sibilings, state based views.

The new design holds the following parts:

  • Url Resolver: url-resolver.js

  • Location Service: very similiar to $location but independently packaged.

  • Url Matcher

  • Route Resolver

  • Route Configuration: this is the api devs will deal with.

The team is also looking at user privilege control hooks.

In future posts we will analyze this in detail. In the meantime, if you would like to read the design document, follow this link

Logging

This subject also came up at the ng-conf. The need of a library that would allow pluggable modules that help logging a much meaningful stacktrace when working with an asynchronous event oriented language such as javascript.

If you would like to look at the source code, follow this diary.js In future posts we will analyze this in detail. In the meantime, if you would like to read the design document, follow this link

Annotations

As mentioned above, metadata is the approach the team has selected to reduce boilerplate and hide angularjs wireframe.

Declarative annotations provides wiring while keeping the readibility for developers to understand what is going on.

Example:

@Provide(Heater)
    export class MockHeater {
      constructor() {}

      on() {
        console.log('Turning on the MOCK heater...');
      }

      off() {}
    }

In future posts we will analyze this in detail. In the meantime, if you would like to read the design document, follow this link and this link

Documentation

Here is some code to look at here

Benchmarking

There are tools out there to evaluate performance on Javascript. benchmark.js, jsperf.com, octane, kraken, robohornet, etc.

The team is trying to leverage karma unit tests and make benchmarking easy to test and easy to run; making sure the results answers one question: “Is this code fast enough?”.

In future posts we will analyze this in detail. In the meantime, if you would like to read the design document, follow this link

Touch/Animations

Team is working on touch devices use cases making emphasis on performance. The main goal is to create a module that implements usage patterns using native browsers features aiming at performance (goal is 60+ FPS).

So far the documentation is still in progress. No code has been published so far.

If you would like to read the design document, follow this link

Package Repository

This subject is more of an infrastructure / distribution concern on how each module (core, complimentary or third party) are being packaged and delivered.

The document presents a great analysis on the different available options.

In future posts we might analyze this in detail. In the meantime, if you would like to read the design document, follow this link

Reference App

During the ng-conf the team announced they will build an AngularJS app. This will serve as a reference on best practices for the community. It will also serve the team presenting real challenges on building a large scale app. So far this team has gained feedback from other teams at Google or from the community what are the challenges when building a large app with Angular.

There is no code or design doc available yet. There is a placeholder here: https://projects.angularjs.org/

In the meantime, you might find interesting a blog post the team did on AngularJS style guide here

During the ng-conf Google Double Click Team made different presentations talking about large scale apps built on AngularJS. You may find all videos at http://ng-conf.ng-learn.org/

Scaffolding

Yeoman, ngTailor are reference conventions set the team is analyzing.

No doc or code examples available yet. In the meantime, there is a published document attempting to gather best recommendations to structure an application. Follow this link.

Build/Deploy

These are more internal topics. Nevertheless, my personal experience has been that we greatly benefit from looking at how this team has setup their CI chain. Hopefully we will gain more insight on these subjects as well.

Notes

Where is Grunt?

As you may see from the different repos, Angular team is already working with GulpJS.

ES6 today

You may also have noticed the need to Transpile ES6 to ES5 in order to use the mentioned modules with a current browser.

Traceur is a JavaScript.next-to-JavaScript-of-today compiler that allows you to use features from the future today. Traceur’s goal is to inform the design of new JavaScript features which are only valuable if they allow you to write better code. Traceur allows you to try out new and proposed language features today, helping you say what you mean in your code while informing the standards process. Traceur

Here is a great review of some of the ES6 language features you can try with Traceur today! Language Features

Join the discussion…


  • What does it mean for the applications currently written in angularJS1.2 version?
    Will you guys also address the migration plan for the 1.2 version applications, if they want to move to angular 2.0 version?

    At high level how painful you guys think the migration would be?

      • <rant>While Angular 2.0 surely looks interesting, I still cannot fully grok the absurdness of all this. If I understand you correctly, you have abandoned Angular, which is used in thousands of applications all over the world. You expect your professional users to explain to their management/customers that for an extended period of time bugfixes and feature development have to be suspended just because the entire front end application has to be rewritten. As a manager I would ask myself when Angular 2 will be replaced by some completely different Angular 3 and if there are any more predictable alternatives (if everything must be rewritten anyway). No feature of Angular 2 can compensate for the amount of trust you are losing with this move. I am really sorry for this rant but this "Meh, let's drop that technology, who cares for users anyway" sounds so much like Google.</rant>

          • This was posted 2 days ago.

            "Once we have an initial version of Angular 2, we'll start to work on a migration path for Angular 1 apps." And "We know that you have invested a lot of time learning how to build web apps with Angular. Since we are preserving most of the core concepts, this knowledge will help you be proficient in Angular 2 much faster."

            http://angularjs.blogspot.se/2...

              • This is true but I can also understand their decision and they said:
                "A reasonable expectation would be that after we release 2.0 final that something like 1.5 - 2 years beyond that we would support 1.3 for things like bug fixes and security patches."

                After the FINAL release (2016?) they will maintain the 1.3 version for almost 2 years (2018). I don't think that changing the architecture like this is a problem. Angular 1.3 is very mature and I think we can make great and organized apps using it and if you have a working AngularJS app right now (or any other app using backbone, ember, ...) I don't think that you can count on using the same code 3 years from now.

                We will have Web Components, ES6 and a lot of new things and if you just try to reuse you code you will loose a lot of the new cool stuff out there. Also 3 years from now you will probabilly have to implement a new UX with new features so you WILL have to use new frameworks/tools anyway.

                  • "No feature of Angular 2 can compensate for the amount of trust you are losing with this move". This sums it all, when times come to migrate, it won't be to Angular 2.0 but to something else.

                    • Angular 1.x already does everything you need to do with the web. You don't have to use Angular2 if you don't want to. Alas, there will come a time when you will start a new project, then you can use A2.

                        • I do not need to mention Angular's migration plan, but I believe Angular needs to change, otherwise it will be a dead framework. It needs to change, because the web changes. It appears every 2 years I after to dramatically change the technology I am using (both front end and back). These changes are good.

                          I would suggest telling your manager/customers that they can continue to use a inferior technology and fall behind, or undergo a serious upgrade. As a manager, it is our responsibility to let the customer know from the beginning how quickly technology changes.

                        • FYI the CSS on this page is chipping off content and causing horizontal scroll bars (Safari Yosemite).

                          The grab below is after i selected text and horizontally scrolled to reveal the hidden text:

                          • Wonder if this proposal will part of Angular 2.0. This make sense when used with ES6 modules and RequireJS optimizer.

                            Ability to add modules to AngularJS runtime AFTER bootstrap
                            https://groups.google.com/foru...

                              • Best video for now on this :

                                . It makes you eager to get it
                                  • Awesome. I also picked up Gulp.js in my build stack. What do you guys think of browserify vs ES6 modules?

                                      • There is some index or central place to look/test angularjs 2.0 sources?

                                        • So, what they're saying is that, like a lot of Google stuff, Angular was half-baked and is to be abandoned. Instead, something all new is being developed and, as Angular's replacement, will also be called Angular. After spending a considerable amount of time learning Angular, I'm realizing that it's a total waste of time. My applications are long lived -- about 10 to 15 years. These are professional applications that cost millions of dollars to develop. They cannot be re-implemented every year or so on the whims of Google's development team.

                                            • WOW i look forward the version 2.0 of AngularJS, hope existant apps will be compatible when we give some modifications

                                                • I want see in Anguar2.0 including Material Design (like Polymer). It's will make ideal web coding.

                                                    • Are there any examples available in Angular 2.0 yet?

                                                        • I created a demo App to showcase ES6 + Annotations with Angular 1.3 https://github.com/xmlking/spa...
                                                          may be helpful for those who cannot wait for Angular 2.0 . You can try live demo at : http://xmlking.github.io/spa-s... (works in latest chrome or firefox)

                                                            • Hello. I now have a large app in 1.2 angular. How does one port to 2.0 angular? Or is it easier to rewrite in something else?

                                                                • Hey Evan, I am curious if you have to rewrite the app or if you could stick with angular 1.2? If rewriting is your preference, how did you evaluate that? Or, how does anyone evaluate that really.

                                                                    • The only way I know how to do that is by performing a cost vs. benefit analysis. Once we have angular 2.0 you can have a sense of what do you need to do to port the app (re-write templates, transform N controllers to directives, etc.) this depends on your specific applications. Then the second step is the benefits you'll gain by doing this (technical debt, features you will get, etc).

                                                                      Once you have a clear picture, you can decide to move to 2.X or to stick with the 1.X version.

                                                                      • Hard to tell yet as AngularJS 2.0 is not there yet. In any case I personally don't think it will be an easy migration as the Angular team is in a lot of cases re-writing things from the scratch.

                                                                        Also on ng-learn.org

                                                                        ABOUT

                                                                        This is a site dedicated to learn AngularJS superheroic framework. AngularJS was designed to make web-applications (or dynamic sites) development easier.

                                                                        Our goal is to help people augment their skills through regular issues covering all aspects of frontend development.

                                                                        2015 © All Rights Reserved ng-learn.org
                                                                        Frederik Dietz
                                                                        Frederik Dietz
                                                                        Frederik Dietz

                                                                        View static HTML