WELCOME TO TITANIUM WEEK! Day Five: Titanium Mobile Best Practices            Kevin Whinnery           Boydlee Pollentine ...
Titanium Mobile Best Practices
KEVIN WHINNERY    DIRECTOR OFDEVELOPER RELATIONS   APPCELERATOR
Agenda  • Architecture    Principles  • Resource    management  • Custom    Components  • Titanium Cookbook  • Q&A
Baseline Best Practices
Titanium App Architecture• Titanium APIs are low level (not Obj-C low  level, but still)• Common question is “how do I str...
Separation of Concerns• You probably already know this, but…• Since Titanium is all JavaScript, it‟s easy  to break• Gener...
Help organize this separation withCommonJS modules
CommonJS Modules• Standard in the JavaScript community• Advantages over Ti.include and the  “module pattern”:  – Secure by...
CommonJS Module Guide on theWiki: http://bit.ly/ti-modules-guide
Obligatory TODO List
TODO List Highlights• Component-oriented UI• Separation of concerns• Well-defined interfaces  – What if I switched data st...
Resource Management
Typically, Memory Management
When Does Titanium Clean Up?• Native UI that provides memory  management (tabs, scrollable)• When windows are closed• When...
What does that mean for you?
Weapons Against Leaks• When possible, use native UI components  that intelligently manage memory• Closing windows will cle...
Forcing Clean-Up/** Most of the time, this will do* the trick…*/var v = Ti.UI.createView();v = null;
Forcing Clean-Up/** But don’t forget about* global listeners!*/var f = function() {…};Ti.App.addEventListener(‘foo’,f);Ti....
Custom Components
Oversimplifying Proxy Objects• Ti.* objects are often “proxies” for native  objects which do native stuff• When you say  v...
Extending Proxies• Often we want to „subclass‟ views like in  the Todo list• Where we run into problems is adding  members...
Custom Component Wrapper
…but more on that Friday.
BOYDLEE POLLENTINE              AUTHORAPPCELERATOR TITANIUM SMARTPHONE APP       DEVELOPMENT COOKBOOK
Any Questions?
Thank You!
Upcoming SlideShare
Loading in …5
×

Best Practices in Mobile Development

2,832 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,832
On SlideShare
0
From Embeds
0
Number of Embeds
841
Actions
Shares
0
Downloads
45
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Best Practices in Mobile Development

  1. 1. WELCOME TO TITANIUM WEEK! Day Five: Titanium Mobile Best Practices Kevin Whinnery Boydlee Pollentine Rick Blalock
  2. 2. Titanium Mobile Best Practices
  3. 3. KEVIN WHINNERY DIRECTOR OFDEVELOPER RELATIONS APPCELERATOR
  4. 4. Agenda • Architecture Principles • Resource management • Custom Components • Titanium Cookbook • Q&A
  5. 5. Baseline Best Practices
  6. 6. Titanium App Architecture• Titanium APIs are low level (not Obj-C low level, but still)• Common question is “how do I structure my app”?• MVC or MVVM is fine – Appc unlikely to adopt a high level framework here• More important – separation of concerns
  7. 7. Separation of Concerns• You probably already know this, but…• Since Titanium is all JavaScript, it‟s easy to break• Generally, we have a few buckets: – UI Components (Construction and Behavior) – Services (Database, Network, Geolocation) – Model Objects
  8. 8. Help organize this separation withCommonJS modules
  9. 9. CommonJS Modules• Standard in the JavaScript community• Advantages over Ti.include and the “module pattern”: – Secure by default – Control public/private interface – No ungainly management of large JavaScript namespaces
  10. 10. CommonJS Module Guide on theWiki: http://bit.ly/ti-modules-guide
  11. 11. Obligatory TODO List
  12. 12. TODO List Highlights• Component-oriented UI• Separation of concerns• Well-defined interfaces – What if I switched data stores? – As long as I maintain my data store interface, I can swap out the underlying implementation if I want
  13. 13. Resource Management
  14. 14. Typically, Memory Management
  15. 15. When Does Titanium Clean Up?• Native UI that provides memory management (tabs, scrollable)• When windows are closed• When a reference to a proxy goes out of scope, and is garbage collected
  16. 16. What does that mean for you?
  17. 17. Weapons Against Leaks• When possible, use native UI components that intelligently manage memory• Closing windows will clean up associated UI resources• Forcing cleanup of unneeded objects
  18. 18. Forcing Clean-Up/** Most of the time, this will do* the trick…*/var v = Ti.UI.createView();v = null;
  19. 19. Forcing Clean-Up/** But don’t forget about* global listeners!*/var f = function() {…};Ti.App.addEventListener(‘foo’,f);Ti.App.removeEventListener(‘foo’,f);
  20. 20. Custom Components
  21. 21. Oversimplifying Proxy Objects• Ti.* objects are often “proxies” for native objects which do native stuff• When you say view.setBackgroundColor(), that triggers special magic in native land• Most of the time that‟s fine, but proxies don‟t „play by the rules‟ of JavaScript
  22. 22. Extending Proxies• Often we want to „subclass‟ views like in the Todo list• Where we run into problems is adding members to proxies• If that becomes necessary, then we need to employ a wrapping JavaScript object
  23. 23. Custom Component Wrapper
  24. 24. …but more on that Friday.
  25. 25. BOYDLEE POLLENTINE AUTHORAPPCELERATOR TITANIUM SMARTPHONE APP DEVELOPMENT COOKBOOK
  26. 26. Any Questions?
  27. 27. Thank You!

×