Presented by Max Beatty
Iris is a full-stack app built with Backbone.js on the client which RESTfully talks to a Node.js server that's able to call our service layer.
Seemslessly embedded inside
Users have no idea they are using a separate technology stack.
A single JavaScript include inside of coreapp loads the Backbone app using RequireJS
use_javascript( "/i/components/requirejs/require.js", '', array("data-main" => "/i/main") );
Initial commit: May 21, 2013
Production Launch: July 15, 2013
Shipped in less than 2 months
Averaging 15 commits per day
100% CoffeeScript
RequireJS
Backbone.js
Node.js
Express
More to come from Ryan
1. User loads page including iris snippet
2. Remotely fetches data from iris server
3. Renders view client-side with Underscore templates in Backbone views
4. Interactions with models and collections are synced to server
define [ 'jquery' 'underscore' 'backbone' 'text!tpl/user/_info.html' ], ($, _, Backbone, tpl) -> class User extends Backbone.View template: _.template tpl className: 'participant clear-both' initialize: -> @model.bind 'change', @render, @ # triggered after fetch render: -> @$el.html @template @model.toJSON()
Promises are objects which represent the pending result of an asynchronous operation
jQuery 1.5 added Deferred which implements Promises
seller = $.Deferred (deferred) => @getSeller options.seller, deferred
getSeller: (sellerIdentity, deferred) -> if sellerIdentity.userUid? seller = new User uid: sellerIdentity.userUid sellerBlock = new UserView model: seller else seller = new Group uid: sellerIdentity.groupUid sellerBlock = new GroupView model: seller seller.fetch error: deferred.fail "error fetching user" success: (model, response, options) -> deferred.resolve sellerBlock.el.outerHTML
Provides a way to execute callback functions based on one or more objects, usually Deferred objects that represent asynchronous events.
$.when( $.ajax("/api") ) .done( (data, status, jqxhr) -> console.log arguments )
Control flow by waiting for both to finish
seller = $.Deferred (deferred) => @getSeller options.seller, deferred buyer = $.Deferred (deferred) => @getBuyer options, deferred $.when(seller, buyer) .done( (sellerResponse, buyerResponse) => @render sellerResponse, buyerResponse[0], buyerResponse[1] options.deferred.resolve @el.outerHTML ) .fail @failedFetch
Feedback?