Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
192
rated 0 times [  197] [ 5]  / answers: 1 / hits: 27021  / 14 Years ago, sun, april 4, 2010, 12:00:00

I have recently started creating an iPhone application using Appcelerator's Titanium. Since the application is essentially all JS, I needed some advice on how I should organize this project.



It's becoming very easy to just create long procedural files for each view in the application. Is there a way I can incorporate MVC, or some structure to the project?



Thanks, I appreciate it.
-Tilo


More From » iphone

 Answers
32

Titanium itself is essentially MVC given that your app.js file is the main controller and each View you create is the view and you pass (or set) model data against the view.



In Titanium, you can decompose your application using a couple of nice built-in mechanisms:




  1. Titanium.include - Titanium.include allows you to include one or more JS files in place much like the C #include compiler directive. You can put common functions and JS classes in this file and then include them where ever you want them imported and available.


  2. Titanium.UI.createWindow - you can create a new View as as a property of the new Window pass in a URL to another JS context which will create a new JS sub-context and allow you to maintain its own variable space (but still give you access back to your parent).




Also, in Titanium, you can create folders that allow you to logically organize your application in a way that is suitable to you and your application.



Edit: Today, the Titanium.Include method is deprecated.
As mentionned in the documentation, we should create a CommonJS module and use the require() statement.



More information about this statement : Require



More information about modules : Modules


[#97166] Wednesday, March 31, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rey

Total Points: 415
Total Questions: 100
Total Answers: 100

Location: Croatia
Member since Fri, Sep 11, 2020
4 Years ago
;