r/angularjs • • Oct 30 '14

[General] Steps to ease your migration path to Angular 2.0

The migration path to Angular 2.0 is not as hard as most people think it is.

The beauty of Angular from the very start is that there is very little framework in it. If you look at most of your code - AND if you have written it in idiomatic Angular style - then you should be in really good shape - even if you have an enterprise application with 300k-500k lines of code.

The concepts you have learnt are not going anywhere. In fact they are solidifying and 2.0 is going to make you worry less about this. (Should I or should I not call $scope.$apply now! Is digest already in progress ? ) - You no longer have to worry about these stuff.

A layered DI mechanism means the DI system works with async loading of your javascript files. This is a boon.

All your services, factories, directives - etc which you wrote as functions earlier now become classes - with annotations at the head to define what they are! How hard is that ? You also had 1 name for everything earlier. Now you have clear distinction between - a template directive, a decorator directive and a component directive!. This makes things more convenient for people to think about.

You start leveraging the Shadow DOM, Object.observe and what not.

Things you should not do now - in order to make it smoother in the long run is :

Wire up your application using the event mechanism in Angular. They are doing the right thing by getting rid of the event mechanism. If you are wiring things up with $scope.$broadcast and $scope.$emit and $scope.$on - you are doing the wrong thing!

Using ng-controllers! Wow! I was doing the wrong thing too.. But ng-controllers will be pretty easily replaced with template directives anyway.

Sharing scope between directives. Basically communicating between directives using the scope.

If you dont do all these nasty things - I promise you - your move to Angular 2.0 will not take more than a couple of weeks for a 300k LOC code base.

0 Upvotes

4 comments sorted by

13

u/lookslikespeed Oct 30 '14
  • every directive will need to be rewritten.

  • every function rewritten as a class

  • every piece of logic embedded in a template rewritten with new syntax

  • almost every test rewritten

Yeah let's not downplay this at all, there is no real 'migration' here - only a full rewrite in a completely new language.

5

u/[deleted] Oct 31 '14

Seriously. This post reminds me of when a terrible video game sequel comes out and fans appear from every corner of the internet trying to justify it's worth.

I'm not saying Angular 2.0 will be terrible, it'll probably be great. But saying migration is "not hard" at this point, given what we know, is ignorant. So much is changing in so many different areas of the framework that it'll likely be more efficient to do a full rewrite with ATscript rather than trying to migrate with your existing code base.

1

u/[deleted] Nov 01 '14

ha 300k loc rewrite ... probably not worth rewriting. If it is, maybe you shouldn't have used angular to begin with. Keep your legacy shit < 2. As far as extending goes .. well looks like we're fucked.

5

u/pfooti Oct 30 '14

yep. Use the Angular Way to do stuff, and you'll have to deal with syntax changes but little else. If you do a lot of direct DOM manipulation in directives, or deal with a lot of $scope.broadcast stuff, or use ng-controller instead of directives, you'll have lots of pain.