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

    var self = this;

    var workWithRevisionGuard = false;
    if (
      this.revisionGuard &&
      !!this.definitions.event.revision && dotty.exists(evt, this.definitions.event.revision) &&
      !!this.definitions.event.aggregateId && dotty.exists(evt, this.definitions.event.aggregateId)
    ) {
      workWithRevisionGuard = true;
    }

    if (dotty.get(evt, this.definitions.event.name) === this.options.commandRejectedEventName) {
      workWithRevisionGuard = false;
    }

    if (!workWithRevisionGuard) {
      return this.dispatch(evt, callback);
    }

    this.revisionGuard.guard(evt, function (err, done) {
      if (err) {
        debug(err);
        if (callback) {
          callback([err]);
        }
        return;
      }

      self.dispatch(evt, function (errs, cmds, sagaModels) {
        if (errs) {
          debug(errs);
          if (callback) {
            callback(errs, cmds, sagaModels);
          }
          return;
        }

        done(function (err) {
          if (err) {
            if (!errs) {
              errs = [err];
            } else if (_.isArray(errs)) {
              errs.unshift(err);
            }
            debug(err);
          }

          if (callback) {
            callback(errs, cmds, sagaModels);
          }
        });
      });

    });

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

    var self = this;

    var workWithRevisionGuard = false;
    if (
      this.revisionGuard &&
      !!this.definitions.event.revision && dotty.exists(evt, this.definitions.event.revision) &&
      !!this.definitions.event.aggregateId && dotty.exists(evt, this.definitions.event.aggregateId)
    ) {
      workWithRevisionGuard = true;
    }

    if (dotty.get(evt, this.definitions.event.name) === this.options.commandRejectedEventName) {
      workWithRevisionGuard = false;
    }

    if (!workWithRevisionGuard) {
      return this.dispatch(evt, callback);
    }

    this.revisionGuard.guard(evt, function (err, done) {
      if (err) {
        debug(err);
        if (callback) {
          callback([err]);
        }
        return;
      }

      self.dispatch(evt, function (errs, cmds, sagaModels) {
        if (errs) {
          debug(errs);
          if (callback) {
            callback(errs, cmds, sagaModels);
          }
          return;
        }

        done(function (err) {
          if (err) {
            if (!errs) {
              errs = [err];
            } else if (_.isArray(errs)) {
              errs.unshift(err);
            }
            debug(err);
          }

          if (callback) {
            callback(errs, cmds, sagaModels);
          }
        });
      });

    });

  }
function ( evt , callback ) { if ( ! evt || ! _ . isObject ( evt ) ) { var err = new Error ( 'Please pass a valid event!' ) ; debug ( err ) ; throw err ; } var self = this ; var workWithRevisionGuard = false ; if ( this . revisionGuard && ! ! this . definitions . event . revision && dotty . exists ( evt , this . definitions . event . revision ) && ! ! this . definitions . event . aggregateId && dotty . exists ( evt , this . definitions . event . aggregateId ) ) { workWithRevisionGuard = true ; } if ( dotty . get ( evt , this . definitions . event . name ) === this . options . commandRejectedEventName ) { workWithRevisionGuard = false ; } if ( ! workWithRevisionGuard ) { return this . dispatch ( evt , callback ) ; } this . revisionGuard . guard ( evt , function ( err , done ) { if ( err ) { debug ( err ) ; if ( callback ) { callback ( [ err ] ) ; } return ; } self . dispatch ( evt , function ( errs , cmds , sagaModels ) { if ( errs ) { debug ( errs ) ; if ( callback ) { callback ( errs , cmds , sagaModels ) ; } return ; } done ( function ( err ) { if ( err ) { if ( ! errs ) { errs = [ err ] ; } else if ( _ . isArray ( errs ) ) { errs . unshift ( err ) ; } debug ( err ) ; } if ( callback ) { callback ( errs , cmds , sagaModels ) ; } } ) ; } ) ; } ) ; }
Call this function to let the saga handle it.
@param {Object}   evt      The event object
@param {Function} callback The function that will be called when this action has finished [optional]
`function(err, cmds, sagaModels){}` cmds and sagaModels are of type Array
Call this function to let the saga handle it .