41
rangle.io The Web Inverted FUTURE PROOF ANGULARJS CEO, rangle.io Nick Van Weerdenburg ARCHITECTURE CTO, rangle.io Yuri Takhteyev

Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

Embed Size (px)

DESCRIPTION

After returning from NG Europe and PhoneGap Day abroad, Nick Van Weerdenburg & Yuri Takhteyev (CEO and CTO from rangle.io) present a talk on How to Embrace Angular 2.0 Today with a Future-Friendly Angular 1.3 Application! We all know Angular 2.0 will leverage ES6, but why wait until later on to reap the benefits of this new language expansion pack? Let's explore what ES6 has to offer and apply these new features to an existing angular app. Let's also see how it improves our testing capabilities and also explore other methods of extending our JS code. Speakers' Bios: Nick is the founder of rangle.io and leads rangle.io's business development, consulting, and enterprise architecture activities. He has 15 years of leadership experience in enterprise software, professional services and marketing. Follow him: @n1cholasv , @rangleio. Yuri is CTO of rangle.io, a former faculty member at the University of Toronto, and a published author, whose interests span software architecture and global software development culture. Follow him: @qaramazov.

Citation preview

Page 1: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

rangle.ioThe Web Inverted

FUTURE PROOF ANGULARJS

CEO, rangle.io

Nick Van Weerdenburg

ARCHITECTURE

CTO, rangle.io

Yuri Takhteyev

Page 2: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

Technology Evolution and Durable Code

Page 3: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

• The future is always different then expected.

• Migrations are challenging.

• Standards-based solutions work best.

• Strong core, flexible edges.

J2EE, Rails, Python 3.0, ActionScript 3.0KEY POINT

Plain JavaScript is the starting point for

reusable code across frameworks or across time

As more of your code runsin the browser, this becomes

essential- legacy servertechniques don’t work

(yet)

Page 4: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

Three Year Plans – Good or Bad?

Page 5: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

• complex requirements

• competing, conflicting requirements

• configurable

• long-lived

• cross-system

Enterprise/Large/Complex Software

Page 6: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

The Future-Proof Solution?

Page 7: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

Standardize on IE6!

Page 8: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

Alternate Solutions?

Page 9: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

Future-Proofish Architectures

With a Solid Pragmatic Cost-Benefit Approach

Page 10: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

Does Angular Pass This Test?

Page 11: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

•D.R.Y

•Structure

•Testability

Soul of Angular (any version)

Page 12: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

• Dependency Injection

• Data binding

• Direectives

• Router

• Filters

• Animations

Features That Don’t Change• Forms

• Expressions

• Protractor

• Karma

• Mocks

Page 13: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

• Mobile

• Material Design shipping with 2.0

• Improved Router

• Performance and Scale

• Standards (ES6)

• Components (merge controllers and directives)

What’s New

Page 14: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

• Well Validated

• Lot’s of prototyping (DI, templates, etc.)

• Lot’s of new ideas testing in AngularDart (used in several internal AngularJS projects)

• External design docs and discussions

• Strong focus on scalability and large project support…this is a benefit that’s gained by migrating from 1.3 when needed

Current Angular 2.0 Status

Page 15: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

Migration EffortFEATURE CHANGE TYPE NOTES VALUE RISK EFFORT

DI Decl ES6, true dependency management, Query HIGH LOW LOW

Modules Decl new syntax, declare dependencies. HIGH LOW LOW

Directives Decl Components, DDO->Classes, Leverage DI HIGH LOW MED

Scope Decl Similar to controller As syntax HIGH LOW* MED*

Controllers Decl Now in components (classes) HIGH MED* MED*

Messaging Imp New model is easier, but different (DI) HIGH MED LOW*

Router Decl 3rd party router can still be used MED LOW* LOW*

Angular 2 Value-Risk Matrix

Page 16: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

But What About Angular 3.0 And Other Future

Innovations?

Page 17: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

Best Practices for TodayThings you should be doing regardless of

your time horizon.

Page 18: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

• Won’t cut it as your “model”

• Lead to entangled code

• Complicate testing

• Can hurt performance

Angular’s Nested Scopes

� Use sparingly.

Page 19: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

Code that can be written without referring to a controller’s scope should be written this way and should be placed in a service.

Page 20: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

• Easy to reason about

• Easy to test

• Avoid entanglement

• Dependency injection (DI) is great

Services

� Use aggressively.

Page 21: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

• Use “controller as”

• Use isolated directives

When Not Using Services

Page 22: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

But what about

Will those methods future-proof your application?

Angular 2.0?

Page 23: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

• Your entangled controllers might be a write-off (though, more on this later)

• “Controller as” controllers might be ok

• You should be able to reuse your services (with a bit of work)

If You Ever Migrate from Angular 1.x

Page 24: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

• Angular-style DI is easy to stub out

• You can then use Angular services without Angular

• You will need to supply the dependencies, though

Services Are Just Modules with DI

Page 25: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

• Allows you to stub out Angular code

• You still get the benefit of DI

Nebular

https://github.com/rangle/nebular

� Treat as a proof of concept

Page 26: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

Converting a Service

var angular = require('nebular');

angular.module('koast-logger', []) .factory('_koastLogger', [ function () {

Page 27: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

Loading a Service

require('./src/core/koast-logger/koast-logger-service');

var nebular = require('nebular');

nebular.instantiateService('_koastLogger');

var logger = nebular.getService('_koastLogger');var log = logger.makeLogger('foo');

log.info('Hello');

Page 28: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

Faking Dependencies

nebular.setService('$q', Q);

Page 29: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

More ModularityEnforcing more modularity will make your life simpler. It also has some immediate

architectural benefits.

Page 30: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

• Write your code as plain JavaScript modules

• Export them an AngularJS services

• Inject AngularJS dependencies if needed

• But: you might reinvent Angular's DI!

Consider Using Plain JavaScript

Page 31: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

• Build a package of "Nebular" services

• Inject actual Angular dependencies

• Export as a single Angular service

• Enjoy more isolation

• Use with or without Angular 1.x

Alternative: Wrapped Services

Page 32: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

Example

require('./src/koast');var nebular = require('nebular');

angular.module('koast') .factory('koast', function($q, $http, $log, $window, $location, $timeout) { nebular.setService('$q', $q); nebular.setService('$http', $http); nebular.setService('$log', $log); nebular.setService('$window', $window); nebular.setService('$location', $location); nebular.setService('$timeout', $timeout); nebular.setService('_', require('lodash')); nebular.setAngularUtils(angular); nebular.instantiateService('koast'); return nebular.getService('koast'); });

Page 33: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

Multi-Framework Applications

We need to be able to build applications mixing Angular 1.2, Angular 2.0, and

NextBigThingJS

Page 34: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

• Encapsulation

• Confinement

Isolation

Page 35: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

• Separate JavaScript contexts

• Components communicate via postMessage()

• Usually used for including 3rd party content

• But could be used for building components

• Requires some plumbing

Sandboxed iFrames and WebWorkers

Page 36: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

Demo

https://github.com/rangle/multi-framework-app

Page 37: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

• iFrame an Angular component

• Represent it as a directive in the parent context

• Or as a web component

Proxy Interfaces

Page 38: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

• Shadow DOM helps with encapsulation, somewhat

• Combine with iFrames for true isolation

• Useful for smaller units

• Can provide a nice wrapper for iFramed widgets

Web Components

Page 39: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

What’s Your Time Horizon?

Page 40: Future-Friendly Angular Applications by Nick Van Weerdenburg & Yuri Takhteyev

rangle.ioThe Web Inverted

CEO, ranale.ioNick Van Weerdenburg

THANK YOU!

@n1cholasv

n1cholasv

CTO, ranale.ioYuri Takhteyev

@qaramazov

yuri