Rails and the single page app
a case study
Jan Krutisch for railswaycon 2012
made with showoff and <3
huhu
z, ? | toggle help (this) |
space, → | next slide |
shift-space, ← | previous slide |
d | toggle debug mode |
## <ret> | go to slide # |
c, t | table of contents (vi) |
f | toggle footer |
r | reload slides |
n | toggle notes |
p | run preshow |
P | toggle pause |
Jan Krutisch for railswaycon 2012
made with showoff and <3
huhu
/halfbyte
Since 1996, more front than backend, etc.
(they're hiring. yep.)
NXT: Snappiness
NXT: Mobile Apps
(taken from designnotes.info)
NXT: Offline Access
FF | Chrome | Opera | IE | Safari | |
---|---|---|---|---|---|
DOM Storage | 3.5 | 5.0 | 10.63 | 8.0 | 5.0 |
WebSQL | - | 4 | 10.5 | - | 3.1 |
IndexedDB | 9.0 | 17 | - | 10 | - |
FF | Chrome | Opera | IE | Safari | |
---|---|---|---|---|---|
DOM Storage | 3.5 | 5.0 | 10.63 | 8.0 | 5.0 |
WebSQL | - | 4 | 10.5 | - | 3.1 |
IndexedDB | 9.0 | 17 | - | 10 | - |
var store = new lawnchair({name:'testing'},
function(store) {
// create an object
var me = {key:'brian'};
// save it
store.save(me);
// access it later...
store.get('brian', function(me) {
console.log(me);
});
}
);
NXT: Clear Boundaries
We've all been there
source: codebrief.com
NXT: Search Engines
<ul class="books">
<li>
<h2>Book Title</h2>
<dl class="metadata">
<dt>ISBN:</dt>
<dd class="isbn">978foobar</dd>
<dt>Authors</dt>
<dd class="creator">Jonathan Oxer, Hugh Blemings</dd>
<dt>Created:</dt>
<dd class="created-at" data-date="2011-01-01">
January 1st, 2011
</dd>
</dl>
</li>
</ul>
books = new App.models.BooksCollection()
ds = new BackboneExt.Deserializer
root: 'ul.books'
iterate: 'li'
selectors:
title: 'h3'
isbn: '.metadata .isbn'
creator: '.metadata .creator'
description:
selector: '.description'
processors: 'strip'
created_at:
selector: '.metadata .created-at'
attribute: 'data-date'
books.reset ds.deserialize()
https://twitter.com/?_escaped_fragment_=/halfbyte
history.pushState(obj, 'foo', 'halfbyte');
history.replaceState(obj, 'foo', 'halfbyte');
Backbone.history.start({pushState: true})
namespace 'api' do
# all the API routes
end
match '/.*', :to => 'home#index'
(beware of the user called 'api')
NXT: Leaving the Rails way
More Complexity
Implement ALL THE CALLBACKS. NXT: Harder to test
<html>
<head>
<script src="jquery-latest.js"></script>
<link rel="stylesheet" href="qunit.css" type="text/css"/>
<script type="text/javascript" src="qunit.js"></script>
<script type="text/javascript" src="book_test.js"></script>
</head>
<body>
<h1 id="qunit-header">QUnit example</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup, will be hidden</div>
</body>
</html>
// a single test
test('should validate ISBN', function() {
expect( 1 );
var book = new Book({isbn: '978-3827324917'});
ok(book.isValid());
});
test('should validate ISBN', function() {
// 1 Assertion expected
expect( 1 );
var book = new Book({isbn: '978-3827324917'});
ok(book.isValid());
});
test('should validate ISBN', function() {
expect( 1 );
// Create a new Book
var book = new Book({isbn: '978-3827324917'});
ok(book.isValid());
});
test('should validate ISBN', function() {
expect( 1 );
var book = new Book({isbn: '978-3827324917'});
// ok() is qunit's assert()
ok(book.isValid());
});
unless Rails.env.production?
match "/javascript_tests/:action",
:controller => 'javascript_tests'
NXT: Browser
LAST
Follow me on twitter for slides-announcement