Cannot extend Ti.App with our own variables anymore?

You must Login before you can answer or comment on any questions.

I have used the Global context and appended variables onto Ti.App to keep simple properties available throughout my app. I understand they are not thread safe, as such I never change them.

In addition to the changes in 1.7.0, I ran across some comments in this question about passing variables that leads me to believe Titanium is going to change something in the future that will cause my applications to break. I would appreciate some clarification from Appcelerator, what changes are coming and how is that going to stop Ti.App extension entirely?

I’m sure other developers are using this and while I understand extending Ti.App has never been recommended per say, without it we are forced to load & reload data on every single window. It’s kind of wasteful and bad for performance. In native iOS development, you can add small things to the AppDelegate and have them available everywhere. I don’t understand why Titanium does not support such a simple concept as global or static classes. Particularly when each window is a new context having a static context available for some common functions would be ideal.

Basically, I want to know if I have to rewrite my entire app, when I will be forced to, and why.

— asked 2 years ago by Vinh Bui
0 Comments

2 Answers

Accepted Answer

you just create your own global context and keep your variables there

Don't pollute the global scope!

here is a blog posting I wrote on it http://blog.clearlyinnovative.com/post/6519148138/titanium-appcelerator-quickie-global-variables-scopes

— answered 2 years ago by Aaron Saunders
answer permalink
11 Comments
  • Aaron, while your answer is in line with what I have seen and does what it does well, I feel it doesn't quite meet the needs of the question asker.

    Your global scope is "global" but the only way you can get at it in sub-contexts is through events. Ti.App allowed you direct access to variables/functions through any window in a synchronous matter (though perhaps not thread safe).

    In order to emulate Ti.App functionality, you have pass namespaces by attaching them to newly created windows, though if the namespace included any functions this is no longer recommended. Also, this of course is not pass by reference, so if your namespace was big there is perhaps a performance penalty of re-evaluating it on every page.

    I feel Titanium should have some kind of static class we could extend. It seems kind of bad style to reload namespaces that don't change on every page. As the question asker commented in native iOS you could always extend the AppDelegate.

    Do you have any experience/workarounds that are more similar to the Ti.App model?

    — commented 2 years ago by Mike Robinson

  • mike, it meets the needs if there is a complete understanding of how to use namespaces in an application

    if you structure your app as directed in the Appcelerator Training, you will see that your entire application is within the global scope you have created and there is no need to pass anything around.

    I would suggest you review the documentation on the wiki and take a look at the TiBountyHunter Application. http://wiki.appcelerator.org/display/td/TCAD+Course+Labs

    — commented 2 years ago by Aaron Saunders

  • another point, this is not an Appcelerator issue, it is an issue regarding understanding how javascript works and how to structure a javascript application which is a foundation upon which to build a mobile application

    — commented 2 years ago by Aaron Saunders

  • Show 8 more comments

Aaron, actually, I think instead of hijacking the original question, we are finally trying to answer the original question. This is what Vihn was asking all along, then Mike joined the chorus. Or at least that is how I took the original question.

A complete paradigm shift away from using separate contexts seems to be not only what is being recommended, but close to mandated if it will be the only way we can use proper namespaces now.

All fine and well for new projects. The question all along has been the impact on existing complex projects, and the best way to make the transition.

— answered 2 years ago by Doug Handy
answer permalink
4 Comments
  • Oops, this was meant for the comment section, not a new answer. Sigh.

    — commented 2 years ago by Doug Handy

  • Aaron, Doug is correct, my intention was to convey the message if I will be force to rewrite my existing application using a completely different paradigm shift due to the 1.7.0 update.

    — commented 2 years ago by Vinh Bui

  • @Doug my apologies, I have taken the discussion offline with Mike because I personally believe it is not a one size fits all answer, maybe it is maybe it isn't but understanding the specific capabilities of an individual and or organization, the problems they have and the requirements of the application and what they are putting in the namespace all play into finding the right answer... that was all i was trying to say.

    — commented 2 years ago by Aaron Saunders

  • Show 1 more comment

Your Answer

Think you can help? Login to answer this question!