JavaScript Framework Smackdown

19
JavaScript Framework Smackdown By: Mike Reyes and Matt Peters

description

Have you ever worked on a website that displayed data dynamically? Are you tired of putting HTML markup inside Javascript? Chances are you’ve looked into using what’s known as an MV* framework. These kind of frameworks aim to help reduce the effort in binding Javascript and JSON data to the user’s screen. Learn more about 3 of the most popular frameworks being talked about in the developer community: Knockout (by a Microsoft employee), Angular (by Google), and Ember (by a Rails and jQuery contributor). We’ll compare and contrast these frameworks and how they ranked against our criteria in building a client-side heavy application that updates its data in real time.

Transcript of JavaScript Framework Smackdown

Page 1: JavaScript Framework Smackdown

JavaScript Framework Smackdown

By: Mike Reyes and Matt Peters

Page 2: JavaScript Framework Smackdown

Users expect more

Interfaces can be complex and dynamicPostbacks don’t cut it anymorePeople are impatient, don’t want to waitA good user experience is now the norm

Page 3: JavaScript Framework Smackdown

Developers are Hyper-Critical

Spaghetti code gets you immediately thrown under the bus

MVC mentality says you don't cross concerns - NO markup in code

Page 4: JavaScript Framework Smackdown

Problems they Solve

Spaghetti code gets you immediately thrown under the bus

MVC mentality says you don't cross concerns - NO markup in code

Page 5: JavaScript Framework Smackdown

Knockout

Middle child at version 2.1

Maintained by a Microsoft employee but not an official Microsoft product

Uses the MVVM pattern

Page 6: JavaScript Framework Smackdown

Ember

Baby of the group, just reached 1.0

Maintained by a Rails and jQuery contributor (+ others)

Uses the MVC pattern

Page 7: JavaScript Framework Smackdown

Angular

Oldest of the three, at 1.0.1

Official Google product

Uses the MVW pattern

Page 8: JavaScript Framework Smackdown

SMACKDOWN!

Page 9: JavaScript Framework Smackdown

Judging Criteria

• Documentation and support• Javascript conventions• Template style• Quirks• Bonus features

Page 10: JavaScript Framework Smackdown

Documentation and Support

• Step-by-step tutorials with code editor

• Interactive examples and code blocks

• 1,120 hits on StackOverflow

Page 11: JavaScript Framework Smackdown

Documentation and Support

• No tutorials for beginners• Several examples with code blocks

but some errata• API documentation has gaps• 784 hits on StackOverflow

Page 12: JavaScript Framework Smackdown

Documentation and Support

• Multiple video tutorials for beginners• Extensive API documentation• In-depth developer guide• 756 hits on StackOverflow

Page 13: JavaScript Framework Smackdown

JavaScript Conventions/Main Object

ViewModel object(s)

function ViewModel() { this.myName = ko.observable("Knockout User"); this.myCars = ko.observableArray([ { name: "Toyota Camry" }, { name: "Ford Taurus" } ]);}App.myMainObject = new ViewModel();ko.applyBindings(App.myMainObject);

Page 14: JavaScript Framework Smackdown

JavaScript Conventions/Main Object

Controller objects

App.myMainObject = Ember.ArrayController.create({ myName: "Ember User", content: [ { name: "Toyota Camry" }, { name: "Ford Taurus" } ]});

Page 15: JavaScript Framework Smackdown

JavaScript Conventions/Main Object

Controller object(s)

function myMainObject($scope) { $scope.myName = "Angular User"; $scope.myCars = [ { name: "Toyota Camry" }, { name: "Ford Taurus" } ]; App.controllerScope = $scope; // not required}

Page 16: JavaScript Framework Smackdown

JavaScript Conventions/Making Changes

function makeChanges() { App.myMainObject.myName("New Name"); App.myMainObject.myCars.push({ name: "Honda Pilot" });}

Properties are converted to methods, that's how it can trigger changes on the screen.The standard Js array methods all work: push, pop, unshift, shift, reverse, sort, and splice.

Page 17: JavaScript Framework Smackdown

JavaScript Conventions/Making Changes

function makeChanges() { App.myMainObject.set("myName", "New Name"); App.myMainObject.pushObject({ name: "Honda Pilot" });}

Properties must be modified with the 'set' method to trigger changes on the screen.The standard Js array methods won't work, but they've added a bunch of handier methods instead.

Page 18: JavaScript Framework Smackdown

JavaScript Conventions/Making Changes

function makeChanges() { App.controllerScope.$apply({ App.myMainObject.myName = "New Name"; App.myMainObject.pushObject({ name: "Honda Pilot" }); });}

Regular Js can be used to manipulate objects but if they're happening outside of Angular's world you must wrap it with a call to $scope.$apply().

Page 19: JavaScript Framework Smackdown