Sha256: 1400e88a9096b827a20cfae45c3ff9878075e110a1b5e0edb704336b1a7502c0

Contents?: true

Size: 1.58 KB

Versions: 4

Compression:

Stored size: 1.58 KB

Contents

Paloma.BeforeCallbackPerformer = function(controller){
  this.controller = controller;
  this.entries = controller.before || [];
  this.action = null;
};

Paloma.BeforeCallbackPerformer.prototype = {

  perform: function(action){
    this.action = action;
    this._executeCallbacks();
  },

  _executeCallbacks: function(){
    for (var i = 0, n = this._callbacks().length; i < n; i++)
      this._executeCallback( this._callbacks()[i] );
  },

  _executeCallback: function(name){
    var callback = this.controller[name];
    if (callback) callback.call(this.controller);
  },

  _callbacks: function(){
    if (this._callbackList) return this._callbackList;

    this._callbackList = [];

    for (var i = 0, n = this.entries.length; i < n; i++){
      var entry = this.entries[i];

      this._callbackList =
        this._callbackList.concat( this._getCallbacksIfForAction(entry) );
    }

    return this._callbackList;
  },

  _getCallbacksIfForAction: function(entry){
    var parsedEntry = this._parseEntry(entry);

    if (
      this._actionIsOn(parsedEntry.actions) ||
      this._allIsOn(parsedEntry.actions)
    )
      return parsedEntry.callbacks;

    return [];
  },

  _actionIsOn: function(actions){
    return actions.indexOf(this.action) != -1;
  },

  _allIsOn: function(actions){
    return actions.indexOf('all') != -1;
  },

  _parseEntry: function(entry){
    var parts = entry.split('->'),
        data = {actions: [], callbacks: []};

    if (parts[0]) data.actions = parts[0].trim().split(' ');
    if (parts[1]) data.callbacks = parts[1].trim().split(' ');

    return data;
  }

};

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
paloma-6.1.0 vendor/assets/javascripts/paloma/before_callback_performer.js
paloma-6.0.0 vendor/assets/javascripts/paloma/before_callback_performer.js
paloma-5.1.0 vendor/assets/javascripts/paloma/before_callback_performer.js
paloma-5.0.1 vendor/assets/javascripts/paloma/before_callback_performer.js