angular-classy icon indicating copy to clipboard operation
angular-classy copied to clipboard

Why angular-classy?

Open trippingtarballs opened this issue 9 years ago • 1 comments

angular-classy is an interesting library, but I'm not sure the docs do enough to answer, "Why angular-classy?"...

  • Is angular-classy simply an extension of your preferences in structuring a Controller, or is there more to it than I realise?
  • Does angular-classy play nicely with unit testing (i.e. karma and jasmine libraries)? In particular, does angular-classy allow for a Controller's unit tests to be written as normal?
  • What relationship does angular-classy have with other sources for opinionated Controller structure?
  • If a Controller function is a constructor in ES5, and has a 1-to-1 relationship with a class in ES6, then what role do you feel angular-classy would play in Angular 2.0?

Many thanks, Raj.

trippingtarballs avatar Mar 18 '15 20:03 trippingtarballs

Is angular-classy simply an extension of your preferences in structuring a Controller, or is there more to it than I realise?

Personally I find it helps me write really structured and readable controllers. I created it only for myself (to begin with) and I find it amazing but I wont say that others should be using it too. It depends on your personal coding style and preferences, maybe have a play with the plunker and see if the syntax feels right for you: http://plnkr.co/edit/Jp4O3d?p=preview

I will highlight one feature though, the plugin system. I'm very proud of it, it is seriously cool and extensible! You can easily add plugins for computed properties or extending other controllers or you can even use element selectors instead of controller names.

Does angular-classy play nicely with unit testing (i.e. karma and jasmine libraries)? In particular, does angular-classy allow for a Controller's unit tests to be written as normal?

Yes. The syntax is different but the semantics are the same. You can write unit tests for controllers in exactly the same way as you normally would. Take a look here for an example: https://github.com/davej/angular-classy/blob/master/test/unit/todoCtrlSpec.js

What relationship does angular-classy have with other sources for opinionated Controller structure?

None really. It does follow lots of best practices though, for example all controller methods are added to the prototype rather than directly to the object. Classy also supports the controllerAs syntax out of the box.

If a Controller function is a constructor in ES5, and has a 1-to-1 relationship with a class in ES6, then what role do you feel angular-classy would play in Angular 2.0?

Classy is an abstraction and already follows the same class pattern as is used in ES6/Angular 2.0 (a 'Classy' class is no different than an ES6 class). This has some interesting implications for transitioning to Angular 2.0 components (née 'controllers'). I have prototyped a version of Classy for Angular 2.0 (it's not public yet) and it exposes almost the exact same API between Angular 1.0 Classy controllers and Angular 2.0 Classy components. This means that you can write a Classy controller/component once and it will be almost completely cross-compatible with both Angular 1.0 and 2.0, without the need for any pre-compilation (Typescript/Traceur). This means you can use Classy now and you will have a really smooth transition to 2.0. There are still a few semantic differences with dependency injection and component services which I am trying to figure out but expect to hear more soon.

Thanks for your questions, I will add them to the FAQ section of the site when I get the chance, let me know if you have any more questions that you'd like me to answer.

davej avatar Mar 18 '15 21:03 davej