Al Veitas
Posts: 0
Joined: Tue Mar 06, 2012 3:43 am

Utilize "Data Mapping" Feature with input from Local Storage

Hi,

Am trying to optimize our application a bit from the perspective of minimizing
REST calls. As an example, we have a login page, where upon the user clicking
on the "Login" button we make a REST call to authenticate. If the REST service
succeeds, we transition to another page ("Home" page) and make another REST call (returns a list of stuff) to populate this page (display a list of stuff).

What we would like to do is eliminate one REST call in the above use case, where our initial authenticate REST call would be modified to return a "list of stuff" that could be used to populate the "Home" page. How could we achieve this? Initial thoughts would be have pseudo-code like this:

Custom JavaScript for Login Button Click Event

----------------------------------------------

Login.execute({});
if (successful) {
store the "list of stuff" json in local storage
transition to "Home" Page
} else {
alert('unable to authenticate');
}

Custom JavaScript for "Home" Page "Load" Event

----------------------------------------------

retreive "the list of stuff" json from local storage (see above Custom JavaScript)
call some tiggzi internal so that we do not make a REST call, but are able to re-use the "Data Mapping" that is defined for the call we do not make anymore

I guess the big question is, is there away to utilize the "Data Mapping" feature that Tiggzi provides but decouple it from a REST call and as a replacement provide the "Data Mapping" feature a json object/list that is in local storage?

If the above pseudo-code is possible, what would the proper API calls be?

Al

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Utilize "Data Mapping" Feature with input from Local Storage

Just to make sure I understand the question. You would like to invoke the mapping but from local storage to page (instead of service to local storage), correct?

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Utilize "Data Mapping" Feature with input from Local Storage

You can do it with Generic Service. Here is an example:

code
$t.myimpl = $t.createClass(null, {

init: function(requestOptions) {
this.__requestOptions = $.extend({}, requestOptions);
},

process: function(settings) {
if (this.requestOptions.echo) {
settings.success(this.requestOptions.echo);
} else {
console.log('Default implementation is used. Please define your own.');

// save JSON data to local storage, this would be your original service call
localStorage.setItem("cacheddata", JSON.stringify({
'name': 'joe'
}));

// load JSON data from local storage
var cdata = localStorage.getItem("cacheddata");

// pass the JSON to the service, for output mapping
settings.success(JSON.parse(cdata));
}
settings.complete('success');
}

});
/code

You would define the service output that matches the JSON you returns. Let me know if this helps.

Return to “Issues”