D O N T ’ S ( A N D D O ’ S ) O F T I T A N I U M D E V E L O P M E N T BY RICHARD LUSTEMBERG Titan, TCAD, working with Titanium since 2010 www.theappartisan.nl
• Not opinionated • About Titanium development • Some other mobile development topics
T O P I C S • Cross platform development • General a. Ti.include b. Globals c. Events d. Memory management
C R O S S P L A T F O R M D E V E L O P M E N T WHAT THE TITANIUM SDKS ISN’T:
A ‘Write once, run everywhere’ platform
Don’t: • Write an application for one platform (ie. iOS), finish it and then expect it to run on another (.ie Android) • Don’t use the default Android emulator
Do: • Test under all platforms incrementally. • Step by step implementation and profiling. • Try using TiShadow simultaneously on several simulator/devices from different platforms Doing as in the two steps above will familiarize you with the platform subtle and not so subtle differences
G E N E R A L T I T A N I U M D E V E L O P M E N T
T I . I N C L U D E ( ) • It’s deprecated • It’s an include (basically a copy & paste), so it loads all code in one go. • If the code is not modularised, it’ll fill up the global space with variables.
• Don’t use Ti.include(), use CommonJS require()
G L O B A L S APP.JS ALLOY.JS
When doing stuff on app.js or alloy.js • Unless you intend to create global variables, wrap all variables using self invoking functions • If you are going to provide globals, then use a namespace to avoid variable collisions
• The Alloy framework instantiates it’s own global variables: Alloy, _ (underscore), Backbone
E V E N T S • Adding listeners the wrong way • Not removing global listeners • Sending improper event payloads
Don't: • Add event listeners from within another event listener • Add event listeners after firing the event
Not removing global events: • Causes memory leaks • Will trigger application crashes when an event callback attempts to work on stale or nulled data.
M E M O R Y M A N A G E M E N T OR NOT CARING ABOUT IT
• Do not: disregard memory management • Do: Clean up your UI objects after no longer using them. Read the literature.