11. Fragmentation Problem
Apple iPhone OS Objective C
Google Android Dalvik Java
RIM Blackberry J2ME Java
Nokia Symbian / MeeGo *
Palm webOS web
Windows Mobile/Phone C,C++,C# (.NET)
13. Cross Platform
• Write once
• Debug everywhere
• Never works...except that whole Internet thing
14. The Web Is a First-class Dev Platform
• Access to native device APIs
• Access to device data
• Great tooling: debugging, logging, testing,
emulation,
and other instrumentation
15. OS Support
• Apple iPhone
• Google Android
• RIM Blackberry
• Palm webOS
• Symbian
• Maemo / MeeGo
• Windows Mobile / Phone
See http://rubyurl.com/jtNs
16. Device APIs / Data
• Geo
• Accelerometer
• Camera / photos
• Vibration
• Contacts
• SMS / telephony
• Sound / video
• Reachability
• Magnometer
• Plus, anything a browser can do
17. PhoneGap does not
prevent you from
augmenting with native
capabilities.
43. DOM Manipulation
// DOM manipulation basics
x$('#protection').html( '<strong>for hard wood</strong>' );
// other hacky ways to hack around
x$('#title').html( 'after', '<p>B.Sc</p>' );
// implicit node creation
x$("<p id='foo'></p>").html('bar'); // <p id="foo">bar</p>
// inner, outer, top, bottom, before, after
x$('#shortcuts').bottom('make life so easy!')
// guess what this does?
x$('#iehack').remove();
// getter
var aboutUrl = x$('a.about').attr('href');
// setter
x$('a.mysite').attr('href','http://westcoastlogic.com');
52. Once You Are Offline
• Cookies
• DOM storage
• SQLite
• Other hacks: flash, window.name, etc.
53. Ghetto, Actually
• DOM Storage is key/value
only; Slightly nicer than
cookies but way lamer
name
• SQLite seems like a bad
idea: schemas, migrations,
impedance mismatch, oh
my
54. Lawnchair Quickly
• JSON document store (not key/value)
• Designed for mobile; very light
• Clean and simple async oo API
• Adaptor pattern for store customization
55. Pull up a Lawnchair!
var people = new Lawnchair({adaptor:'dom'});
56. Adding Records
// Saving a document
var me = {name:'brian'};
people.save(me);
// Saving a document async
people.save({name:'frank'}, function(r) {
console.log(r);
});
// Specifying your own key
people.save({key:'whatever', name:'dracula'});
57. Finding Records
// Get that document
people.get(me.key, function(r){
console.log(r);
});
// Returns all documents as an array to a
callback
people.all(function(r){
console.log(r);
});
// List all with shortcut syntax
people.all('console.log(r)');
58. Removing Records
// Remove a document directly
people.get(me.key, function(r){
people.remove(me);
});
// Remove a document by key
people.save({key:'die', name:'duder'});
people.remove('die');
// Destroy all documents
people.nuke();
60. Searching / Finding
// Iterate documents conditionally!
// The first function is a conditional.
// The second is a callback exec on records returned by the first
people.find(
function(r) {return r.name == brian},
function(r) {console.log(r)}
);
// Iterate conditionally via shorthand
people.find('r.name == "brian"', 'console.log(r)');
// You can mix and match shorthand btw
people.find('r.name == "brian"', function(r){
console.log(r)
});