Best Optimal way to handle api/luna request between controller and service

What is best optimal way for calling any api or luna api from controller to serivce and make api request from serivce,
and again response to controller from service success.
in other words, any deferred and promise related concept as well?

Comments

  • edited June 2015
    Some good starting points would be:
    The developer guide, which discusses how to use models, collections, sources, and how to create your own source for an api.

    For use of the luna api, I think this page might help you along a bit: http://developer.lge.com/webOSTV/develop/web-app/how/manage-local-data/

    Finally, enyo doesn't implement it's own promise implementation but models and collections do have success and fail callbacks which you could wrap with a promise implementation of your choice. Something like:
    var refreshCollection = function(collection) {
      var promise = new Promise();
      collection.fetch({
        success: function() {
          promise.resolve();
        },
        fail: function() {
          promise.reject();
        }
      });
      return promise;
    };
    
    var collection = new enyo.Collection();
    refreshCollection(collection).then(function() {
      alert('data loaded!');
    });
Sign In or Register to comment.