best practices in mobile development

27
WELCOME TO TITANIUM WEEK! Day Five: Titanium Mobile Best Practices Kevin Whinnery Boydlee Pollentine Rick Blalock

Upload: appcelerator-inc

Post on 11-May-2015

2.591 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Best Practices in Mobile Development

WELCOME TO TITANIUM WEEK!

Day Five: Titanium Mobile Best Practices

Kevin WhinneryBoydlee Pollentine

Rick Blalock

Page 2: Best Practices in Mobile Development

Titanium Mobile Best Practices

Page 3: Best Practices in Mobile Development

KEVIN WHINNERY

DIRECTOR OFDEVELOPER RELATIONS

APPCELERATOR

Page 4: Best Practices in Mobile Development

• Architecture Principles

• Resource management

• Custom Components

• Titanium Cookbook

• Q&A

Agenda

Page 5: Best Practices in Mobile Development

Baseline Best Practices

Page 6: Best Practices in Mobile Development

• 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

Titanium App Architecture

Page 7: Best Practices in Mobile Development

• 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

Separation of Concerns

Page 8: Best Practices in Mobile Development

Help organize this separation with CommonJS modules

Page 9: Best Practices in Mobile Development

• 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

CommonJS Modules

Page 10: Best Practices in Mobile Development

CommonJS Module Guide on the Wiki: http://bit.ly/ti-modules-guide

Page 11: Best Practices in Mobile Development

Obligatory TODO List

Page 12: Best Practices in Mobile Development

• 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

TODO List Highlights

Page 13: Best Practices in Mobile Development

Resource Management

Page 14: Best Practices in Mobile Development

Typically, Memory Management

Page 15: Best Practices in Mobile Development

• 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

When Does Titanium Clean Up?

Page 16: Best Practices in Mobile Development

What does that mean for you?

Page 17: Best Practices in Mobile Development

• When possible, use native UI components that intelligently manage memory

• Closing windows will clean up associated UI resources

• Forcing cleanup of unneeded objects

Weapons Against Leaks

Page 18: Best Practices in Mobile Development

/** Most of the time, this will do* the trick…*/

var v = Ti.UI.createView();v = null;

Forcing Clean-Up

Page 19: Best Practices in Mobile Development

/** But don’t forget about * global listeners!*/var f = function() {…};Ti.App.addEventListener(‘foo’,f);Ti.App.removeEventListener(‘foo’,f);

Forcing Clean-Up

Page 20: Best Practices in Mobile Development

Custom Components

Page 21: Best Practices in Mobile Development

• 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

Oversimplifying Proxy Objects

Page 22: Best Practices in Mobile Development

• 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

Extending Proxies

Page 23: Best Practices in Mobile Development

Custom Component Wrapper

Page 24: Best Practices in Mobile Development

…but more on that Friday.

Page 25: Best Practices in Mobile Development

BOYDLEE POLLENTINE

AUTHOR

APPCELERATOR TITANIUM SMARTPHONE APP DEVELOPMENT COOKBOOK

Page 26: Best Practices in Mobile Development

Any Questions?

Page 27: Best Practices in Mobile Development

Thank You!