Adventures in Facebook®: Lessons Learned from a Landmark webOS App

25

description

The Facebook app team shares tips and tricks directly from the Facebook playbook that will help make your own webOS apps easier to create and maintain. Get the inside scoop on techniques they developed for debugging, data management, and common webOS tasks. Open source included.

Transcript of Adventures in Facebook®: Lessons Learned from a Landmark webOS App

Page 1: Adventures in Facebook®: Lessons Learned from a Landmark webOS App
Page 2: Adventures in Facebook®: Lessons Learned from a Landmark webOS App

Adventures in Facebook®:

Lessons Learned from a Landmark webOS App

Kevin DeckerDeveloper Relations Engineer

April 24, 2010

Page 3: Adventures in Facebook®: Lessons Learned from a Landmark webOS App

Best Practices

Debugging

Tools

Classes and Libraries

Open Source

Agenda

Page 4: Adventures in Facebook®: Lessons Learned from a Landmark webOS App

Best Practices

Page 5: Adventures in Facebook®: Lessons Learned from a Landmark webOS App

Widgets

• Problem• Duplicated UI and

backing logic throughout the app

• Maintenance nightmare

• Solution• Custom Mojo™ widgets

Page 6: Adventures in Facebook®: Lessons Learned from a Landmark webOS App

Widgets

• Class in Mojo.Widget namespace• setup function

•Renders HTML

•Registers events

• cleanup function•Unregisters events, etc.

• All Mojo APIs available• Reference class by name in x-mojo-element

attribute

Page 7: Adventures in Facebook®: Lessons Learned from a Landmark webOS App

Widgets—Advanced

• Subwidgets• controller.instantiateChildWidgets(controller.element)

• controller.exposeMethod• Mojo.Event.send

Page 8: Adventures in Facebook®: Lessons Learned from a Landmark webOS App

Avoid Document References

• Multiple stage = multiple documents• Execution occurs in data document • Consequences:

• References to document object will fail•document.getElementById

•document.querySelector

• Mojo.Controller.stageController• Prototype extensions may fail

Multiple stage readiness

Page 9: Adventures in Facebook®: Lessons Learned from a Landmark webOS App

Avoid Document References

• Fixes:• document.getElementById

•sceneController.get

• document.querySelector•sceneController.sceneElement.querySelector

• Mojo.Controller.stageController•sceneController.stageController

•Mojo.appController.getActiveStageController

• $(elId).x()•Form/Element.x(sceneController.get(elId))

Multiple stage readiness

Page 10: Adventures in Facebook®: Lessons Learned from a Landmark webOS App

Periodic Tasks

• Two methods:• palm://com.palm.power/timeout service• setInterval

• Limited to app lifetime: setInterval• Outliving app: Timeout service

Page 11: Adventures in Facebook®: Lessons Learned from a Landmark webOS App

Debugging

Page 12: Adventures in Facebook®: Lessons Learned from a Landmark webOS App

Inspecting Multistage Applications

• Process/document under Multistage• Data document• Stage documents

• applicationManager service• bit.ly/aQFnuF

• stage-inspect script• github.com/kpdecker/stage-inspect

Page 13: Adventures in Facebook®: Lessons Learned from a Landmark webOS App

Logging

• Error.prototype.toString• Function wrappers

• wrapInLogger• wrapInErrorHandler

•DebugLogging.wrapInErrorHandler(

"Mojo.Controller.SceneController”,

[ "assistantSetup", "assistantCleanup" ]);

• traceWrapper• Exceptions are not logged in API callbacks

DEBUGGING ONLY

Page 14: Adventures in Facebook®: Lessons Learned from a Landmark webOS App

Tools

Page 15: Adventures in Facebook®: Lessons Learned from a Landmark webOS App

Tools

• palm-run• Build+execution utility

•Build

•Deploy

•Launch

•Log

• github.com/dalmaer/palm-run

• i18nScanner• Scans for untranslated JavaScript and HTML strings• Generates report of i18n tokens• github.com/kpdecker/i18nScanner

Page 16: Adventures in Facebook®: Lessons Learned from a Landmark webOS App

Classes and Libraries

Page 17: Adventures in Facebook®: Lessons Learned from a Landmark webOS App

Operation Queue

• Frequently need to block multiple calls on a method• Init callbacks• Dataset refresh

• OperationQueue• queue• getSuccessHandler• getErrorHandler

Login

Notify

Status

Page 18: Adventures in Facebook®: Lessons Learned from a Landmark webOS App

Observer Manager

• Alternative to sendEventToCommanders and sendToNotificationChain APIs

• Notifications while scene/stage inactive

• Deferred notifications

• ObserveManager• setup• cleanup• observe• stopObserving

Page 19: Adventures in Facebook®: Lessons Learned from a Landmark webOS App

Service Request Wrapper

• Mojo.Service.Request maintain weak reference• Garbage collection can

prevent callback

• ServiceRequestWrapper• request

• Same signature as Mojo.Service.Request

• Maintains references

• Cancels completed requests

• Similar to scene serviceRequest

Page 20: Adventures in Facebook®: Lessons Learned from a Landmark webOS App

Caching Data

• Remote data sources• Potentially broken

connections• User expectations

• CacheManager• Depot wrapper• Simplifies init, access,

and expiration• load

• store

Page 21: Adventures in Facebook®: Lessons Learned from a Landmark webOS App

Paging Data Source

• Many data sources only differ in a few places

• Examples• Event List• Profile Wall

• Common needs:• Paging• Arbitrary size• Caching

• DataModelBase• getRange

• Look ahead algorithm

• refresh• Subclasses:

• loadRange• getCacheName

Page 22: Adventures in Facebook®: Lessons Learned from a Landmark webOS App

Continuously Loading Paged List

• UI companion to paged data list• Transparently handles page loading

• Refresh indicator

• Mojo.Widget.PagedList• <div id=“listName”

x-mojo-element=“PagedList”></div>• this.controller.setupWidget("listEvents", {

itemTemplate: "events-list/events-item-template”,

emptyTemplate: "events-list/events-empty-template”,

hasNoWidgets: true

}, this.eventList);

Page 23: Adventures in Facebook®: Lessons Learned from a Landmark webOS App

Open Sourced

• All of the libraries open sourced• github.com/palm/webos-samples

• Further details (to come)• incaseofstairs.com

Page 24: Adventures in Facebook®: Lessons Learned from a Landmark webOS App

&Q A

Page 25: Adventures in Facebook®: Lessons Learned from a Landmark webOS App