Duplicated function calls #13048
-
Assume you want to run some code only once after the app started. For example if you want to safe some files to local storage as it mentioned here, because it is unnecessary to execute (also to check if files already created) each time the index controller is called. Is this unnecessary operation handled by sdk or js-interpreter or do I have to take care in code? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
How would the SDK decide if that function is unnecessary to call a second time? You have to do that yourself and a simple if check at the beginning is nothing expensive especially if it doesn't run expensive functions that are not needed. Otherwise you can check for a file if you want to make sure that it exists! Keep in mind that it might be deleted somewhere else and your variable is still true but you have to recreate it. |
Beta Was this translation helpful? Give feedback.
How would the SDK decide if that function is unnecessary to call a second time? You have to do that yourself and a simple if check at the beginning is nothing expensive especially if it doesn't run expensive functions that are not needed.
You can use Ti.App.Properties for that: https://titaniumsdk.com/api/titanium/app/properties.html have a look at the examples and especially the
getBool
method. Check if with default:false and set it to true at the end of your if block. Next time you start your app it will be true and the if will be ignored.Otherwise you can check for a file if you want to make sure that it exists! Keep in mind that it might be deleted somewhere else and your variable is…