switching enterprise-level angularjs 1.x apps to 2...is it worth upgrading to angular >=2.0 ? l...

29
Switching Enterprise-level AngularJS 1.x Apps to 2.0 Souvik Basu, Freelance JavaScript Developer and Trainer, MeanHub

Upload: others

Post on 23-May-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

Switching Enterprise-level AngularJS 1.x Apps to 2.0Souvik Basu, Freelance JavaScript Developer and Trainer, MeanHub

Page 2: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

ENTERPRISE APPS

Page 3: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

What defines an Enterprise app?

l Larger code basel Created over a period of time

l Big Feature List l With hundreds of Routes

l Distributed teaml Typically Geographically separatedl Varied skill levels

l Existing User basel Hundred thousand or even million

l High amount of Transactions per secondl With high availability of Service

Page 4: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

What are the needs of an Enterprise app?

l Backward compatibility l Cannot afford to break older deployments in use

l Frequent Releasesl Time to market is importantl Feature list is ever growing

l Solid CI pipelinel Automation for regressionl Continuous delivery (preferably)

l QA across a big siteLarge QA teams who need faster releases of features

.

Page 5: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

What parameters are we interested in?

l Debugabilityl While upgrading from 1.x to 2, all code cannot be debugged

l Performance l Performance of application should be acceptable during the upgrade

l Understandabilityl Clean code for upgradel Ramp up of team on new technologies

l Refactoring and toolingl IDE should work with both versions for refeactoringl Auto completion

l .

Page 6: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

Is it worth upgrading to Angular >=2.0 ?

l Benefitsl Faster bootstrapl Future proof

l ES6l Active development, Community support

l Can handle large number of objects in Modell Better handling of Application complexity

l Component based architecturel Emulated - Shadow DOMl Module based DI

l Better Change Detectionl AOT

l

Page 7: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

Is it worth upgrading to Angular >=2.0 ?

l Downsidel Learning Curve

l TypeScript, ES6 l JavaScript Modules, classes, arrow function, event handlingl Obervables, RxJSl Module loaders l Styling binding to DOM properties rather than attributesl Input, Output, EventEmitter, Router, Providers.. .. ..

l Existing Team Skillsl Unpredictability during Upgradel Support by 3

rd

Part libs

Page 8: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

Is it worth upgrading to Angular >=2.0 ?

l Downsidel Size of the application

l Actually this is the MOST important point!

Page 9: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

PREPARATION FOR UPGRADE

Page 10: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

Did you follow Best Practices?

l Test Coveragel Unit, Integration, Screenshot, Compilation testsl Tests Automationl Enough Test Coverage

l Angular Best Practicesl Component based designl Single component per filel Divide application into modulesl Avoid using private variables in AngularJS lib ($$)

Page 11: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

Did you follow Best Practices?

l Loggingl Error Handling

l Abstraction Layersl Reuse componentsl DRY. Avoid copy paste of code

l Full SPAl Install dependencies using npml Use .service() instead of .factory()

Page 12: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

UPGRADE STRATEGIES

Page 13: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

Big Bang or Incremental?

l Big Bangl Small and Medium size appsl Messed up Enterprise Appsl Enough Time to Market and Budgetl All New Projectsl Autonomous teams

l Incrementall For Enterprise apps currently deployed in productionl Small Agile teams: Small iterative fixes l Distributed teams

Page 14: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

Big Bang or Incremental?

l Bangalore 1.0 → Bangalore 2.0l

l

l

l

l

l

l Increasing User base Accommodate more Usersl Already in Production High Performancel Slow Infra Handle more features and complexitiesl Better UX. More green cover

Page 15: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

Big Bang or Incremental?

l Problems with creating a New Bangalore 2.0 city from scratchl Very High Cost of Creationl Long time of Development and Completionl Complexity in migrating existing population to new cityl Where to create new Multiplexes and Shopping Malls?

l New city or Old city?

l Advantages of Creating a New Bangalore 2.0 city (e.g. Amaravati)l Very well planned l 10 lane roads throughout the cityl Well created using latest tools and machineryl Lesser bugs (and potholes!)

Page 16: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

INCREMENTAL UPGRADE

Page 17: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

Ways to do Incremental Upgrade

l Use Existing AngularJS app and upgrade components to Angular one by one

l Component by Componentl Feature by Feature (Route by Route)l Module by Module

l ngUpgradel Dependency Injectionl Component Nestingl Content Projection / Transclusionl Change Detection

Page 18: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

Step 0

l Bridging the gapl JavaScript → TypeScriptl Concatenated all.js → Modulesl Module loaders

l Webpackl System.jsl Browserify

l Bootstrapping AngularJS and Angular side by sidel Angular inside AngularJS or AngularJS inside Angular?

Page 19: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

Top Down or Bottom Up?

https://github.com/souvikbasu/angular-upgrade

Page 20: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

Migrating Services

l Rewrite if possiblel Since there is no hierarchy of servicesl Services are plain classes

Page 21: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

Migrating Routes

l Use AngularJS as well as Angular Routes togetherl <router-outlet></router-outlet>

l <div ng-view></div>

l Routes per modulel Separate Modules for AngularJS and Angular

l

Page 22: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

Migrating Filters → Pipes

Page 23: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

Migrating Tests

l Significant changes in Unit tests to match current codel Protractor tests using angular matchers will need minor

modificationsl ng-repeatl ng-model

protractor-conf.js → ng12Hybrid: truel

Page 24: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

Watch out

l Finish off the Upgrade as soon as possiblel Certain things do not work in Upgrade

templateUrlstyleUrls

l You need to add the upgraded Angular component in entryComponents to use in AngularJS

l Do not try to include AngularJS component into Angular.. it gets messy soon

l

l

Page 25: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

What about 4.0 and beyond?

l Releases every 6 monthsl Only upgrade npm packages

l

l

npm i @angular/common@next @angular/compiler@next

@angular/core@next @angular/forms@next @angular/http@next

@angular/platform-browser@next @angular/platform-browser-

dynamic@next @angular/platform-server@next @angular/router@next

typescript@latest --S -E

npm i @angular/compiler-cli@next --D -E

Page 26: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

REFERENCES

Page 27: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

References

https://angular.io/docs/ts/latest/guide/upgrade.html

https://blog.thoughtram.io/angular/2015/10/24/upgrading-apps-to-angular-2-using-ngupgrade.html

https://docs.google.com/document/d/1xvBZoFuNq9hsgRhPPZOJC-Z48AHEbIBPlOCBTSD8m0Y/edit

https://vsavkin.com/migrating-angular-1-applications-to-angular-2-in-5-simple-steps-40621800a25b

Page 28: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

Thank you@souvikbasu

Page 29: Switching Enterprise-level AngularJS 1.x Apps to 2...Is it worth upgrading to Angular >=2.0 ? l Benefits l Faster bootstrap l Future proof l ES6 l Active development, Community support

www.modsummit.com

www.developersummit.com