Live data from Hacker News

Classy: Cleaner class-based controllers for AngularJS

davej.github.io

51–59 of 59 posts

Re: Classy: Cleaner class-based controllers for AngularJS

#51

There's a lot of conversation about the redundant injector syntax in this thread. This is something that ngmin takes care of completely transparently. There's really no need to worry about it in raw, uncompressed source code. Other than that, this provides a nice way to enforce a certain set of conventions, but I'm not completely sold on the quality of those conventions - the most glaring thing being losing reference…

ngmin isn't really a solution, it's a post processing transpiler hack. There's lot of ways to format your js code so that ngmin does the wrong thing and destroys working code. I wouldn't call the problem 'solved'. At least not until angular 2.0 or a solution like this.

Re: Classy: Cleaner class-based controllers for AngularJS

#52
post #12

Oh wow, this is my little project, cool to see it on the front page of Hacker News. :-)

It's a really nice demo page. What do you use for the code highlighting?

Thank you. It's just CSS and the :hover pseudo-selector, the popover effect is done using CSS keyframe animations.

Fun geek fact: The Mac OS style close/minimize/expand buttons on the code editor are written in CSS, they're not images. A bit of a pointless exercise but a fun little easter egg.

Re: Classy: Cleaner class-based controllers for AngularJS

#54
post #16
post #9

Typescript classes work nicely with Angular controller I find. Coffeescript ones too.

Afaik you cant declare anonymous classes in typescript,let alone wrapping them in a closure. No problem with Coffeescript. module.controller 'MainCtrl', class constructor:($scope,bar,baz)-> $scope.message="foo" @$inject = ['$scope','bar','baz'] that's why i prefer the later.types or not.

I don't use anonymous classes for controllers so that's not an issue for me but if you want to use them, I don't think there's a way to do it in typescript

Re: Classy: Cleaner class-based controllers for AngularJS

#55
post #31

Earlier quoted context omitted.

I can see Classy adding value, but repetition with dependency injection is a solved problem if you use ngmin[1]. [1]: https://github.com/btford/ngmin

I disagree that ngmin is a full solution to the problem. It is a good and very helpful tool, but it's a hack and a pretty leaky one - I think it's often less of a hassle to just write all the explicit injection syntax myself than to fiddle with formatting to get ngmin to work and track down issues when it doesn't. Classy's solution seems much nicer to me.

I have no idea what you're talking about; I've never had any issues with ngmin or angular's default (i.e. non-array / string) injection methods.

Re: Classy: Cleaner class-based controllers for AngularJS

#56
post #24
post #3

I guess this can clean logic flow in a controller, but here you end up with a bloated object instead. The biggest problem I see though is if you want to save a reference to the unregister functions of the $watch callbacks. Otherwise, this is a cool idea, although it falls a little short.

> The biggest problem I see though is if you want to save a reference to the unregister functions of the $watch callbacks. This is a valid criticism, thank you. I will try to put together a nice solution for this. Of course you can always register/de-register watchers the normal way inside of the init method.

Yup, I'm aware - nice work on this so far!

Re: Classy: Cleaner class-based controllers for AngularJS

#57

Earlier quoted context omitted.

I disagree that ngmin is a full solution to the problem. It is a good and very helpful tool, but it's a hack and a pretty leaky one - I think it's often less of a hassle to just write all the explicit injection syntax myself than to fiddle with formatting to get ngmin to work and track down issues when it doesn't. Classy's solution seems much nicer to me.

I have no idea what you're talking about; I've never had any issues with ngmin or angular's default (i.e. non-array / string) injection methods.

I guess your mileage may vary, but in my experience, it isn't difficult to write reasonable code that ngmin fails to handle properly, and it's difficult to debug when it happens. It seems the best thing to do is to start with ngmin from the get-go and adopt a style guide that works with it. But I like the idea of a library that abstracts it away altogether.

Re: Classy: Cleaner class-based controllers for AngularJS

#58
post #29

This is actually great for someone learning Angular. It's just a different way of presenting the exact same material. I was completely dumbfounded at first when learning Angular. This would have helped. I very much suggest everyone interested in Angular development to read what the guys at MeanJS.org[1] have to say about structuring modules. It helps me think about my app a lot better. The structure could be cleaned…

Very nice! I am doing a project with angularjs right now to learn and it's really interesting. If you have other resources that explain how to do things the right way it would be welcome.

Re: Classy: Cleaner class-based controllers for AngularJS

#59
post #12

Oh wow, this is my little project, cool to see it on the front page of Hacker News. :-)

My initial run-through of it leaves me thinking it's absolutely brilliant, which isn't generally a word I use lightly.

So long as non-Classy controllers are still operable (which I assume they are), then I should be able to port individual controllers one at a time without disturbing un-ported controllers, then this is exactly what Angular was needing, IMO.

Post reply on HN