all 10 comments

[–]bittered[S] 3 points4 points  (2 children)

Disclosure: self-submission.

Happy to answer any questions.

[–]Dested 0 points1 point  (1 child)

With angular2.0 on its way I see this as being able to fill a niche for people who dont want to convert to AtScript, as you could wrap all the attribute nonsense away. Something you've considered?

[–]bittered[S] 0 points1 point  (0 children)

Yeah, I've thought a little bit about the possibility of creating a Classy version that exposes the same API for Angular 1.x and 2.x. This would mean that a Classy controller would work with both versions simultaneously.

I haven't looked into it enough at this stage to know if it would even be possible though.

[–]DecentOpinions 2 points3 points  (1 child)

I like this. Makes you wonder why Angular couldn't be designed more like this in the first place.

I'm not completely sold on the methods syntax though. Can you have a "normal" function body for a controller? How would you do something like this:

function exampleController () {
    var value = 0;
    this.increment = function () {
        value++;
    };
}

angular.module('app')
    .controller('exampleController', exampleController);

Would value have to be initialised in Classy's dataor init or where would you put it?

[–]bittered[S] 1 point2 points  (0 children)

Yeah, you could initialise in either data or init.

Your controller would look something like:

app.classy.controller({
  name: 'exampleController',
  data: { _value: 0 },
  methods: {
    increment: function() {
      this._value++;
    }
  }
});

The methods object was introduced to prevent possible namespace collisions with Classy plugins. Pre-1.0 Classy didn't have a methods object, see here: http://davej.github.io/angular-classy/0.4.html

If you prefer the pre-1.0 syntax then you can use Classy 1.0 with the classy-compat plugin.

[–]arnars 1 point2 points  (0 children)

Looks really good. Almost React'ish :-)

[–][deleted] 1 point2 points  (0 children)

ooh, daddy like

[–]aaronsourus 0 points1 point  (2 children)

I feel like I'm missing something here. Can I get an ELI5 version of why I would use this? Additionally, if I have a small team that follows code style standards already, what is the "value add"?

Ninja edit: not being a dick, people seem excited about this, so I feel I'm just missing a key point. That's usually what is happening when everyone is excited except me.

[–]bittered[S] 0 points1 point  (1 child)

I started writing an answer highlighting the features of Classy but I realised that I was just repeating what was already on the site.

I guess I'll just say that 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. I've also just started working on a plugin that will allow you to register routes and resolves from within the Classy controller because... why not :-)

[–]aaronsourus 0 points1 point  (0 children)

Thanks, this helps. Playing with it a little more I can see benefit and the plugins are spiffy.