angular for rubyists

20
AngularJS for Rubyists It’s like sinatra but for clients Tom Cartwright @tomcartwrightuk keepmebooked.com tomcartwright.net

Upload: tom-cartwright

Post on 21-Feb-2017

394 views

Category:

Technology


0 download

TRANSCRIPT

AngularJS for RubyistsIt’s like sinatra but for clients

Tom Cartwright @tomcartwrightuk

!keepmebooked.com

tomcartwright.net

Framework or library?

Library Framework

It has conventions (well sort of)

EmberBackbone Angular

Rails setup

This blank template is needed to stop rails freaking out - there is almost certainly a better way of handling this.

config/routes.rb

app/controllers/angular_controller.rb

app/views/angular/app.html.erb

Define an app

Setup some routingapp/assets/javascripts/app/app.js

…and a controllerapp/assets/javascripts/app/controllers.js

A rendered page

As if by magic…some binding occurs

…but how?

Dirty checkingCheck $scopes and copy

Check again against the copies

Repaint DOM if required

Server communication

$resource service

app/assets/javascripts/app/resources.js

Err.. no

app/assets/javascripts/app/resources.js

app/assets/javascripts/app/controllers.js

Promises

Testing

For unit testing - use Jasmine

spec/javascripts/controller…/dashboardControllerSpec.js

spec/javascripts/controller…/dashboardControllerSpec.js

Huzzah!

Directives

The API is doesn’t have to be the source of truth

Thank you $watching

Github ・Twitter @tomcartwrightuk

$scope.$watch('forQuestions', ! function(silence, question) {! console.log(possibleEruditeResponse);! }!});

Like the sound of this AngularJS stuff? Keepmebooked is hiring