Reputation: 4254
I started working on a Titanium application which is Content and data call intensive application.
I need some guidance regarding the best practices to be followed when building such application. I am pretty much aware of the commonJS approach. I want to know best-practice coding to limit or eliminate memory/cacheing problems in Appcelerator. How do one approach or deal with these issues?
Thanks
Upvotes: 0
Views: 130
Reputation: 21
I use a hybrid of MVC and M V VM I came up with:
MVC is appropiate for web URLs for redirectint yoursite/user and take the user as a param. Hence the Controller is the point of entry of the applicaiton.
In .net's MVVM pattern, the View is the Point of entry of the application. View requests ViewModel (connect events to UI) and ViewModel requests to Business (Model). Finally when data is reached, the data is "reflected" through event bubbling. This sounds cumbersome but it really ain't
Using that same approach I use the following
UI > C > B > Tech > Internet
And on Controller I suscribe Events, where in Tech I triggered them.
Where "Tech" abstracts all technical (SQLite, JSON, Ti.App.Properties, etc)
The Business knows Entities and Icons, but no technical aspect
getIcon('Badge'){ tech.getIcon('Badge') } )
Where in technical we could have a dictionary like var
getIcon(icon)
{
var Icon = {
'Badge': 'src/cfg/img/badge.png'
}
return Icon[icon]
}
So the controller would look something like:
oTable = ui.TableEmployees() // our custom made TableView at 'ui.js'
Ti.App.addEventListener( 'EmployeesUpdated', function(e){ oTable.data = e.data } )
lastly, everytime I need to update info, I go
business.refreshEntity('Employees')
where business access Tech
tech = require('src/tech')
refreshEntity(entity){ tech.refreshEntity(entity) }
finally in tech
refreshEntity(entity)
{
HTTPClient = new Ti.Network.HTTPClient( { onload:..., onerror:... } )
HTTPClient.send()
data = transform(response)
if (data != cachedData)
Ti.App.fireEvent( 'EmployeesUpdated', {data: data} )
}
That way you can have pull on refresh-es, timers, etc. and ONLY if the data changed then you promote it to all your affected views
Upvotes: 2