Sha256: a57e40d1eb4e65ffc3b66bad6cf5cf9836f95e86164dcbeac7f10e22e3c82089

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

(function(Paloma){

  var Engine = function(config){
    this.router = config.router;
    this.factory = config.factory;
    this.restart();
  };


  Engine.prototype.start = function(){
    for (var i = 0, n = this.requests.length; i < n; i++){
      var request = this.requests[i];

      console.log('Processing request with params:');
      console.log(request.params);

      var controllerName = this.router.controllerFor(request.resource),
          action = request.action,
          redirect = this.router.redirectFor(request.resource, action);

      if (redirect){
        controllerName = redirect['controller'];
        action = redirect['action'];
      }

      console.log('mapping <' + request.resource + '> to controller <' + controllerName + '>');
      console.log('mapping action <' + request.action + '> to controller action <' + action + '>');

      var Controller = this.factory.get(controllerName);

      if (!Controller){
        return console.warn('Paloma: undefined controller -> ' + controllerName);
      }

      var controller = new Controller(request.params);

      if (!controller[action]){
        return console.warn('Paloma: undefined action <' + action +
                            '> for <' + controllerName + '> controller');
      }

      controller[action]();
    }
  };


  Engine.prototype.restart = function(){
    this.requests = [];
  };


  Engine.prototype.request = function(resource, action, params){
    this.requests.push({resource: resource,
                        action: action,
                        params: params});
  };


  Paloma.Engine = Engine;

})(window.Paloma);

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
paloma-3.0.0 vendor/assets/javascripts/paloma/engine.js