Code coverage report for src/wreqr.commandStorage.js

Statements: 94.44% (17 / 18)      Branches: 75% (3 / 4)      Functions: 100% (5 / 5)      Lines: 94.44% (17 / 18)     

All files » src/ » wreqr.commandStorage.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59        1 1     1 6 6   6           1           15     15     6           6     15           3 3         5 5       1    
// Wreqr.CommandStorage
// --------------------
//
// Store and retrieve commands for execution.
Wreqr.CommandStorage = (function(){
  "use strict";
 
  // Constructor function
  var CommandStorage = function(options){
    this.options = options;
    this._commands = {};
 
    Iif (_.isFunction(this.initialize)){
      this.initialize(options);
    }
  };
 
  // Instance methods
  _.extend(CommandStorage.prototype, Backbone.Events, {
 
    // Get an object literal by command name, that contains
    // the `commandName` and the `instances` of all commands
    // represented as an array of arguments to process
    getCommands: function(commandName){
      var commands = this._commands[commandName];
 
      // we don't have it, so add it
      if (!commands){
 
        // build the configuration
        commands = {
          command: commandName, 
          instances: []
        };
 
        // store it
        this._commands[commandName] = commands;
      }
 
      return commands;
    },
 
    // Add a command by name, to the storage and store the
    // args for the command
    addCommand: function(commandName, args){
      var command = this.getCommands(commandName);
      command.instances.push(args);
    },
 
    // Clear all commands for the given `commandName`
    clearCommands: function(commandName){
      var command = this.getCommands(commandName);
      command.instances = [];
    }
  });
 
  return CommandStorage;
})();