Book Image

Appcelerator Titanium: Patterns and Best Practices

By : Boydlee Pollentine , Trevor Ward
Book Image

Appcelerator Titanium: Patterns and Best Practices

By: Boydlee Pollentine , Trevor Ward

Overview of this book

<p>Titanium Mobile has quickly become the platform of choice for many mobile developers and is growing and changing at a rapid rate. From the implementation of CommonJS,&nbsp; MVC design patterns and more, the last year in Titanium development has been a rollercoaster of change for the better. With this knowledge at your disposal you’ll be creating top quality, highly capable and stable apps in no time.<br /><br />This book shows you exactly how to implement all the latest Titanium Mobile best practices into your apps, from a thorough explanation of CommonJS with plenty of examples, through to structuring a complete MVC style codebase. With advanced topics such as implementing patterns and utilizing ACS, through to a thorough investigation of CommonJS and prototype, this book will take you from Titanium Novice to Titanium Ninja in no time!<br /><br />"Appcelerator Titanium: Patterns and Best Practices" starts off with some explanations on JavaScript practices and advanced topics, before getting stuck into the new CommonJS pattern and using that to implement MVC-style architectures for your application. It continues in a practical, hands on manner, explaining how to perform cross device layouts with different techniques, and how to implement SQL alternatives such as JSONDB.<br /><br />The book discusses some of the major advanced JavaScript topics, such as prototype and micro optimizations, before leading the developer into a thorough explanation of the CommonJS pattern, MVC implementation and advanced topics such as SQL alternatives and implementing designs for cross device layouts.</p>
Table of Contents (12 chapters)

Do not pollute the global object


Within an application you can define various application objects. Declare and use these with caution, as they use up resources and can easily cause clashes with other private and local objects. Application-level variables are not really required and should be avoided. If you require a small piece of data to move around the application, consider using persistent data or passing it to the required modules.

Application-level event handlers are required for various tasks including, amongst others, background services and geolocation. If you do use them, always remove them when they are no longer needed. To control the flow of an application, you may need to set up a global listener, but you only need one with a common function to control the flow. This will be seen in more detail in the next chapter.

Note

In CommonJS there is no global scope; declaring a variable within a module makes it private to that module. Declaring variables in app.js as Ti.App.varName =...