290 likes | 477 Views
JS. Play-By-Play Announcer: Todd Bashor todd@TheStartersAcademy.com. Image credit: http:// www.mobygames.com /images/shots/l/73414-mtv-celebrity-deathmatch-windows-screenshot-title-screens.jpg. VS. Background image credit : nicksarebi on Flickr. VS. 3. AGE. 3. 1.0.0. CURRENT.
E N D
JS Play-By-Play Announcer: Todd Bashor todd@TheStartersAcademy.com Image credit: http://www.mobygames.com/images/shots/l/73414-mtv-celebrity-deathmatch-windows-screenshot-title-screens.jpg
VS Background image credit: nicksarebi on Flickr
VS 3 AGE 3 1.0.0 CURRENT 1.2.0-RC.2 18 RELEASES 55 2753 ISSUES CLOSED 3577 21 ISSUES OPEN 623 19.4KB WEIGHT 81.4KB
Round 1: Learnability “…perhaps easy to adopt because it’s so minimal” -Steven Sanderson “The learning curve of AngularJS can be described as a hockey stick.” -Matt Frisbie
Round 2: Separation of Concerns - Model Sync Collection View - - Router Events Module Scope $http, $resource - View Directive Filter $routeProvider, $location Controller, $...
Round 2: Separation of Concerns View varHelloView= Backbone.View.extend({ template: _.template($('#hello-template').html()), events: {"click button": "doSomething"}, render: function(){ $(this.el).html( this.template( this.model.attributes)); return this; }, doSomething: function(e){ /*do something*/} }); varhelloView= new HelloView({model: greeting}); $("body").append(helloView.el); helloView.render(); Model var Greeting = Backbone.Model.extend({}); var greeting = new Greeting({title: ”World"}); DOM <script type=“text/template” id=“hello-template”> <p>Hello <%= title %></p> <button>OK</button> </script>
Round 2: Separation of Concerns Image credit: http://docs.angularjs.org/guide/concepts
Angular Directive <input todo-blur="doSomething(todo)"> todomvc.directive('todoBlur', function () { return function (scope, elem, attrs) { elem.bind('blur', function () { scope.$apply(attrs.todoBlur); }); }; });
BACKBONE STILL UP BY 1
Round 3: Templating Pick your favorite template engine underscore handlebars dust ejs jade … Decorate the DOM
Round 3: Templating <script type="text/template" id="item-template"> <div class="view"> <input class="toggle" type="checkbox” <%= completed ? 'checked': '' %>> <label><%- title %></label> <button class="destroy"></button> </div> <input class="edit" value="<%= title %>"> </script>
Round 3: Templating <div class="view"> <input class="toggle" type="checkbox" ng-model="todo.completed"> <label ng-dblclick="editTodo(todo)">{{todo.title}}</label> <button class="destroy" ng-click="removeTodo(todo)"></button> </div>
Round 4: Routing varTodoRouter = Backbone.Router.extend({ routes: { '*filter': 'setFilter’ }, setFilter: function (param) {…} }); app.TodoRouter = new TodoRouter(); Backbone.history.start();
Round 4: Routing vartodomvc = angular.module('todomvc', []). config(['$routeProvider', function($routeProvider) { $routeProvider .when('/:state', { templateUrl: 'index.html', controller: todomvc.TodoCtrl }) .otherwise({redirectTo: '/'}); }]); <div ng-view></div>
Round 5: Testability beforeEach(function () { this.model= new app.Todo(); this.view= new app.TodoView({ model: this.model }); });
Round 5: Testability it("should set focus for editing", function () { // Must call render to populate element for // `$input` this.view.render(); varspy = sinon.spy(this.view.$input, "focus"); this.view.edit(); expect(spy).to.be.calledOnce; });
Round 5: Testability /*global inject, expect, angular*/ describe('todoFocus directive', function () { varscope, compile, browser; beforeEach(inject( function ($rootScope, $compile, $browser) { scope = $rootScope.$new(); compile = $compile; browser = $browser; })); //snip });
Round 5: Testability describe('SetFocusdirective', function() { varscope, element, timeout; beforeEach(inject(function($rootScope, $compile, $timeout) { timeout = $timeout; scope = $rootScope.$new(); element = angular.element('<input set-focus="inFocus" />'); $compile(element)(scope); scope.$digest(); })); it('sets the input to be focussed when inFocus message is broadcast', function() { scope.$broadcast('inFocus'); timeout.flush(); expect(scope.focusedElement).toEqual(element); }); });
Round 6: Reusability Plugins Directives Filters Services
Round 7: Community 192 CONTRIBUTORS 397 1,268 WATCHERS 1,577 15,810 STARS 14,842 29,181 STACKOVERFLOW 34,295 76 BOOKS 55
TIED! 3 ROUNDS EACH
Round 8: Fit for Purpose Fix your jQuery Enhance your page Play well with other libraries Take HTML to a new level Build serious CRUD apps Maintain large apps
Learn More angularjs.org todomvc.com egghead.io github.com/jmcunningham/AngularJS-Learning backbonejs.org todomvc.com backbonetutorials.com github.com/addyosmani/backbone-fundamentals Todd Bashor todd@TheStartersAcademy.com