www.webOShelp.net

Get the latest on:webOS Developers' RSS FeedwebOS Facebook page webOS Twitter Feed

Home Forums

The www.webOShelp.net WebOS / Mojo Developers' Forum

WebOS Mojo Development => Mojo Newbies => Topic started by: SeanBlader on March 19, 2009, 03:19:37 PM



Title: Model-View-Controller
Post by: SeanBlader on March 19, 2009, 03:19:37 PM
http://en.wikipedia.org/wiki/Model-view-controller

View is what the user sees, that would be the HTML.
Controller is the Javascript that manipulates the data.

So what's the model do other than hold data. Had to ask my boss this one, he's a much better educated and experienced software developer than myself. He says that the Model is actually also labeled as services that are called to get access to the data. So in the webOS case it would be the SQL and it's container functions that are used to get access to the data saved on the client side.

Unfortunately table data doesn't accept object data very conveniently, and this is something that I'll be figuring out for the config data I have already for the alarm clock. The list of alarms and the list of world clocks is easy, but what about this object:

      SPIN.data = {
         alarmset: [],
         config:  {
            snooze: 10,
            limit: '1:00',
            tone: '',
            locations: [],
            local: {}
         }
      };

So the alarmset and the locations are easy to format into a table, I'll just have to pull locations out of the config area. But what about the rest? Array's can't have 3 items because you'd need an index number, but a datatable can, so maybe if we format like this:

1 snooze 10
2 limit 1:00
3 tone alarm.mp3
4 local San Francisco

Then I could probably loop through that and create an object like this:
var config = {
for(var i=0; i < table.length; i++) {
 table[1]: table[2],
}
}

Um, but you can't have a loop run inside an object, that's just a flat out syntax error by the interpreter. So you have to use the loop to generate a string that you can then parse into an object with prototype.

var configString = "{";
for(var i=0; i < table.length; i++) {
 configString += table[1] + ":'" + table[2] + "',";
}
configString += "}";

That *should* get you a json string that you'd then use prototype to parse like this:

var data = configString.evalJSON();

I'm writing this at work, partially to just figure it out for myself, but also partially to let y'all in on the process of not only figuring stuff out, but maybe making a really cool little tool for us to use later to get object data into a client side data storage table and then back out. I didn't actually run the code here, and you'd need something in table that was pulled out of the Client Storage, but for psuedo-code that's close to the real code, it's pretty close.

The only way to test it at the moment is with Safari 3.2 or 4 beta... or maybe Chrome? Firefox doesn't have the HTML5 draft spec data storage capabilities yet. But basically this is a step up from using a cookie for the same effect that DOES work in IE6+ and Firefox 2+. I'll come back and update this post with the actual results once I migrate from a Cookie which I'm using now and get it to work using Client Storage. But that's how development goes, well in my head kinda.