from angular to angular 2 via the upgradeadapter

22
Whoami? • Tony May @_tonymay • Founded my own agency to act as a technical co-founder for startups (Primary stack ng1 + ng-material + ionic) • Some corporate consulting Like William Hill (a crazy hybrid 50% iOS + 50% ionic = 110% awesome) • Currently working at identitii – startup working on blockchain (Ethereum) POCs for correspondent banks (Ng1/2 + Ng Material, Node & Golang)

Upload: tony-may

Post on 14-Apr-2017

216 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: From Angular to Angular 2 via the UpgradeAdapter

Whoami?

• Tony May @_tonymay• Founded my own agency to act as a technical co-

founder for startups (Primary stack ng1 + ng-material + ionic)

• Some corporate consulting Like William Hill (a crazy hybrid 50% iOS + 50% ionic = 110% awesome)

• Currently working at identitii – startup working on blockchain (Ethereum) POCs for correspondent banks (Ng1/2 + Ng Material, Node & Golang)

Page 2: From Angular to Angular 2 via the UpgradeAdapter

From Ng1 to Ng2 (and beyond)

• Step 1: Javascript -> Typescript• Step 2: Grunt/Gulp -> Webpack• Step 3: Ng2 Bootstrapping• Step 4: Decide on Strategy

(inside out vs outside in)• Step 5: Optimise + Minimise

Page 3: From Angular to Angular 2 via the UpgradeAdapter

A note on comparisons

False dichotomy: a logical fallacy which involves presenting two opposing views, options or outcomes in such a way that they seem to be the only possibilities: that is, if one is true, the other must be false, or, more typically, if you do not accept one then the other must be accepted. The reality in most cases is that there are many in-between or other alternative options, not just two mutually exclusive ones.

Page 4: From Angular to Angular 2 via the UpgradeAdapter

From Ng1 to Ng2 (and beyond)

• Step 1: Javascript -> Typescript• Step 2: Grunt/Gulp -> Webpack• Step 3: Ng2 Bootstrapping• Step 4: Decide on Strategy

(inside out vs outside in)• Step 5: Optimise + Minimise

Page 5: From Angular to Angular 2 via the UpgradeAdapter

Steps to implement

• tsconfig• npm • typings for existing

dependencies

• choose your output directory

• rename *.js -> *.ts • sudo rm -rf /

Step 1: Javascript -> Typescript Why: It’s a SUPERset ;-) of javascriptWhy: Interfaces are awesome (refactor like a boss)

Page 6: From Angular to Angular 2 via the UpgradeAdapter
Page 7: From Angular to Angular 2 via the UpgradeAdapter

To ng2 (beyond)

• Step 1: Javascript -> Typescript• Step 2: Grunt/Gulp -> Webpack• Step 3: Ng2 Bootstrapping• Step 4: Decide on Strategy

(inside out vs outside in)• Step 5: Optimise + Minimise

Page 8: From Angular to Angular 2 via the UpgradeAdapter

Primarily: A different philosophy

Angular• .config()• .decorate()• .$broadcast

Angular 2• Pre-compile via packager• Pre-compile via packager• RXJS LIKE A BOSS!

Step 2: Bower -> NpmWhy: does everything bower does + moreWhy: Seems like everyone is now on-board the npm train

Page 9: From Angular to Angular 2 via the UpgradeAdapter

Build Pipeline

Angular1. Packages: Bower2. Build: Grunt/Gulp3. Javascript4. JSLint5. Write Code6. Package7. Optimise/Minimise

Angular 21. Packages: Npm2. Build: Webpack3. Typescript4. Typings5. Package/Transpile6. Write Code7. Optimise/Minimise

Page 10: From Angular to Angular 2 via the UpgradeAdapter
Page 11: From Angular to Angular 2 via the UpgradeAdapter

From Ng1 to Ng2 (and beyond)

• Step 1: Javascript -> Typescript• Step 2: Grunt/Gulp -> Webpack• Step 3: Ng2 Bootstrapping• Step 4: Decide on Strategy

(inside out vs outside in)• Step 5: Optimise + Minimise

Page 12: From Angular to Angular 2 via the UpgradeAdapter
Page 13: From Angular to Angular 2 via the UpgradeAdapter

Angular1 with Angular2 Angular2 with Angular1

Page 14: From Angular to Angular 2 via the UpgradeAdapter

Summary

• ForwardRef is necessary, and you will have a big pita if you try and use export with the Upgrade Adapter

• The debugging is sometimes tricky, especially when you have multiple frameworks nested

• The Ng1 & Ng2 types are IN THE METHOD NAME!!

• app(‘main’).factory(‘blah’, downgradeNg2Provider(Ng2Provider))

Page 15: From Angular to Angular 2 via the UpgradeAdapter

To ng2 (beyond)

• Step 1: Javascript -> Typescript• Step 2: Grunt/Gulp -> Webpack• Step 3: Ng2 Bootstrapping• Step 4: Decide on Strategy

(inside out vs outside in)• Step 5: Optimise + Minimise

Page 16: From Angular to Angular 2 via the UpgradeAdapter

I Can Has?

• Ng1 with Ng2 children? Yes• Ng2 with Ng1 children? Yes• Ng1 with Ng2 children, with Ng1 children?

Probably not• Ng2 with Ng1 children, with Ng2 children?

Probably not• $broadcast? Hell no, use observables!!

Page 17: From Angular to Angular 2 via the UpgradeAdapter

Main Component

(w router)

Search View Detail View

ButtonPredictive Search Menu

Hero Provider

Example Application Structure

Page 18: From Angular to Angular 2 via the UpgradeAdapter

Main Component

(w router)

Search View Detail View

ButtonPredictive Search Menu

Hero Provider

Outside In Upgrade2

3

1

Page 19: From Angular to Angular 2 via the UpgradeAdapter

Main Component

(w router)

Search View Detail View

ButtonPredictive Search Menu

Hero Provider

Inside Out Upgrade

32

1

Page 20: From Angular to Angular 2 via the UpgradeAdapter

Mistakes, I had had my few

• Tried outside in to start, with my angular material Ng1 app, OMG, DO NOT DO THIS. When I first tried this, it was not rendering, not giving a console message, so I had use the force to debug

• Didn’t know about observables so I implemented ng-redux to replace a component that relied on $rootScope.$broadcast :-P and had to change everything back once I worked out observables

• Thinking you could just “drop in” Angular 1 components, I wish it was that simple.

Page 21: From Angular to Angular 2 via the UpgradeAdapter

To Ng2 (and beyond)

• Step 1: Javascript -> Typescript• Step 2: Grunt/Gulp -> Webpack• Step 3: Ng2 Bootstrapping• Step 4: Decide on Strategy

(inside out vs outside in)• Step 5: Optimise + Minimise

Page 22: From Angular to Angular 2 via the UpgradeAdapter

Out of TIME!• Basically, the new html syntax can have some issues with webpack 2 beta gulification,

uguficaltoin, uglification. I’ve found that webpack 1 is currently better because you get a smaller bundle size, and better transpile support (espeically if you use Google Closure Compilier)

• You get the best result if you cherry pick the includes, (e.g. // Only import the rxjs bits that you needimport 'rxjs/Observable’;import 'rxjs/add/operator/toPromise’;import 'rxjs/add/operator/map’;import 'rxjs/Subject’;import 'rxjs/BehaviorSubject’;

) then rely on the CommonsChunk webpack plugin to… well.. chunk the common libraries.

• Final size is super important, imho you will need to include Ng2+Rx (~140kB min+compress) Ng1 (~50kB min+compress) + other libraries so you need to get the final bundle as small as possible.

• I’ll post some code examples of each step on github, on Friday!• Join the telegram group, I’m happy to answer any questions you have!

https://telegram.me/joinchat/DhJ-lgmRdB-mkBh5Nk6GHQ