lib/commandDispatcher.js
function (cmd, callback) {
    if (!cmd || !_.isObject(cmd)) {
      var err = new Error('Please pass a valid command!');
      debug(err);
      throw err;
    }

    if (!callback || !_.isFunction(callback)) {
      var err = new Error('Please pass a valid callback!');
      debug(err);
      throw err;
    }

    var target = this.getTargetInformation(cmd);

    var commandHandler = this.tree.getCommandHandler(target);

    // if (!commandHandler) {
    //   commandHandler = this.tree.getCommandHandlerByOldTarget(target);
    // }

    if (!commandHandler) {
      var err = new Error('No command handler found for ' + target.name);
      debug(err);
      return callback(err);
    }

    if (!this.commandBumper) {
      return commandHandler.handle(cmd, callback);
    }

    var key = target.context + target.aggregate + target.aggregateId + dotty.get(cmd, this.definition.id);

    this.commandBumper.add(key, function (err, added) {
      if (err) {
        return callback(err);
      }

      if (!added) {
        return callback(new DuplicateCommandError('Command already seen!'));
      }

      commandHandler.handle(cmd, callback);
    });
  }
function (cmd, callback) {
    if (!cmd || !_.isObject(cmd)) {
      var err = new Error('Please pass a valid command!');
      debug(err);
      throw err;
    }

    if (!callback || !_.isFunction(callback)) {
      var err = new Error('Please pass a valid callback!');
      debug(err);
      throw err;
    }

    var target = this.getTargetInformation(cmd);

    var commandHandler = this.tree.getCommandHandler(target);

    // if (!commandHandler) {
    //   commandHandler = this.tree.getCommandHandlerByOldTarget(target);
    // }

    if (!commandHandler) {
      var err = new Error('No command handler found for ' + target.name);
      debug(err);
      return callback(err);
    }

    if (!this.commandBumper) {
      return commandHandler.handle(cmd, callback);
    }

    var key = target.context + target.aggregate + target.aggregateId + dotty.get(cmd, this.definition.id);

    this.commandBumper.add(key, function (err, added) {
      if (err) {
        return callback(err);
      }

      if (!added) {
        return callback(new DuplicateCommandError('Command already seen!'));
      }

      commandHandler.handle(cmd, callback);
    });
  }
function ( cmd , callback ) { if ( ! cmd || ! _ . isObject ( cmd ) ) { var err = new Error ( 'Please pass a valid command!' ) ; debug ( err ) ; throw err ; } if ( ! callback || ! _ . isFunction ( callback ) ) { var err = new Error ( 'Please pass a valid callback!' ) ; debug ( err ) ; throw err ; } var target = this . getTargetInformation ( cmd ) ; var commandHandler = this . tree . getCommandHandler ( target ) ; // if (!commandHandler) { //   commandHandler = this.tree.getCommandHandlerByOldTarget(target); // } if ( ! commandHandler ) { var err = new Error ( 'No command handler found for ' + target . name ) ; debug ( err ) ; return callback ( err ) ; } if ( ! this . commandBumper ) { return commandHandler . handle ( cmd , callback ) ; } var key = target . context + target . aggregate + target . aggregateId + dotty . get ( cmd , this . definition . id ) ; this . commandBumper . add ( key , function ( err , added ) { if ( err ) { return callback ( err ) ; } if ( ! added ) { return callback ( new DuplicateCommandError ( 'Command already seen!' ) ) ; } commandHandler . handle ( cmd , callback ) ; } ) ; }
Dispatches a command.
@param {Object}   cmd      The passed command.
@param {Function} callback The function, that will be called when this action is completed.
`function(err, evts){}`
Dispatches a command .