It’s just data

Angular.rb example

Tim Bray: If hating this is wrong, I don’t want to be right.

Perhaps you would like this better?  :-)

module Angular::X

  controller :LoginController do
    @credentials = {username: '', password: ''}

    def login(credentials)
      AuthService.login(credentials).then {
        broadcast! AUTH_EVENTS.loginSuccess
      }.catch {
        broadcast! AUTH_EVENTS.loginFailure


Try it here.

Things to note:

More examples, from deployed code: roster, agenda.

This will be the covered by my ApacheCon talk.

What would the idiomatic Ruby look like for the formAutofillFix code, as I believe that was the code Tim was actually calling out (It has functions nested 4 deep).  I’m assuming he would be just as annoyed by:

Posted by Kevin H at

Kevin: do you know enough about Angular.js to answer the following question: is that simply defining an implicit compile function?  If so, I can update my filters to accommodate such a usage pattern.

Assuming the answer to my question is yes, the answer to your question is that there would be one less end, as function(...) {return function(...) {...}}; would be replaced with a single do...end.

I’ll also bet that Tim’s issue isn’t so much with the curly braces, but the need to accompany only some of them with a close parenthesis, and only some of them with a semi-colon.  In other words, it is not the nesting, but rather the requirement on the programmer to keep track on how to properly close each of the nettings.

P.S.  My understanding is that semicolons are a statement separator and not a statement terminator in JavaScript, as such, each of these semicolons (with the possible exception of the last one) are unnecessary.

Posted by Sam Ruby at

is that simply defining an implicit compile function?

Per the docs, it appears that the answer is a “yes, but...”, more specifically:

Best Practice: Prefer using the definition object over returning a function.

Posted by Sam Ruby at

Add your comment