davej / angular-classy

Cleaner class-based controllers with Angular 1
http://davej.github.io/angular-classy/
813 stars 27 forks source link

Classy Services #20

Closed MiracleBlue closed 8 years ago

MiracleBlue commented 10 years ago

Hey there, I've noticed that it's been a month since any commits were made. Is Classy Services still in development? If not, I might be able to help because I plan to use this as part of my work, but I'd like to have all common angular things be done consistently before I jump into it.

Thanks!

davej commented 10 years ago

Yes, everything is still in development it's just that finding the time at the moment is difficult. Any open-source contributions are welcome :+1:

If you have any questions on development just ask. :)

MiracleBlue commented 10 years ago

Heh, I know that feel for sure man. I've also got so many things I want to do but just can't find the time. However, if I can get us to adopt Classy controllers here at work, I can probably put down some time to contribute to a services addition. I'll give it a shot!

Keep up the great work btw, this is a fantastic bit of code you have here :)

anthony-ism commented 10 years ago

Hey, great work btw, I love the idea of classy. I have adopted it for use on a project me and my guys have been working on. It keeps our controllers uniform. One day I thought, I wonder what a classy service would look like. I looked to see if there was any development and figured just spend some time trying to implement it myself.

I was able to get something going. Most of it is really just copying what was done for the controllers and making minor tweaks for the service. I am not quite finished, however I am kind of stuck because I really can't see any added benefit. It actually makes it a little more difficult to work with because when in an anonymous function, "this" refers to the current function, rather than the service object, I work around this by defining a parent variable (var parent = this;) before getting into the functions scope, and use that when trying to reference anything in the service.

Also, the classy service exposes all the private variables, as opposed to just the function necessary.

I am going to continue to try to make this actually useful, any feedback would be great.

If you are at all interested in what I came up with (its rather simple) or would like to discuses some ideas you might have had for this, I am willing to take any ideas and attempt to implement them.

wuxiaoying commented 10 years ago

I use classy for all my controllers and most directives now, but I didn't really see a point in classy services. I feel like services are already classes (whatever you use in javascript for classes, obviously really nice in CoffeeScript), when you declare them with angular.service.

For example in CoffeeScript most of my services look like

class MyService
    constructor: (@Dependency1, @Dependency2) ->

module.service 'MyService', ['Dependency1', 'Dependency2', MyService]
davej commented 10 years ago

I share the general sentiment here. I have played around with doing Classy services too but I didn't feel like the benefits were obvious (like with Classy Controllers). I'm still open to the idea of doing services but I would need to see some obvious benefits over doing it the vanilla way.

MiracleBlue commented 10 years ago

Yeah, maybe. I'm just a fan of consistent syntactical sugar.

On Thu, Jul 10, 2014 at 6:49 PM, Dave Jeffery notifications@github.com wrote:

I share the general sentiment here. I have played around with doing Classy services too but I didn't feel like the benefits were obvious (like with Classy Controllers). I'm still open to the idea of doing services but I would need to see some obvious benefits over doing it the vanilla way.

— Reply to this email directly or view it on GitHub https://github.com/davej/angular-classy/issues/20#issuecomment-48579556.

davej commented 10 years ago

I would be happy to consider it if somebody designed an API with a brief usage example, but simply wrapping a vanilla service in app.classy.service({ }) seems a bit superfluous.

MiracleBlue commented 10 years ago

Sure, I guess it is. I don't think I'm well versed enough in Angular to know how one could make services better, if at all ;)

If I think of something I'll let ya know.

On Thu, Jul 10, 2014 at 6:56 PM, Dave Jeffery notifications@github.com wrote:

I would be happy to consider it if somebody designed an API with a brief usage example, but simply wrapping a vanilla service in app.classy.service({ }) seems a bit superfluous.

— Reply to this email directly or view it on GitHub https://github.com/davej/angular-classy/issues/20#issuecomment-48580241.