lib/block/Decision.js
function Decision (arg1, arg2) {
  var decision, choices;

  if (!(this instanceof Decision)) {
    throw new SyntaxError('Constructor must be called with the new operator');
  }

  if (typeof arg1 === 'function') {
    decision = arg1;
    choices = arg2;
  }
  else {
    decision = null;
    choices = arg1;
  }

  if (decision) {
    if (typeof decision !== 'function') {
      throw new TypeError('Parameter decision must be a function');
    }
  }
  else {
    decision = function (message, context) {
      return message;
    }
  }

  if (choices && (typeof choices === 'function')) {
    throw new TypeError('Parameter choices must be an object');
  }

  this.decision = decision;
  this.choices = {};

  // append all choices
  if (choices) {
    var me = this;
    Object.keys(choices).forEach(function (id) {
      me.addChoice(id, choices[id]);
    });
  }
}
function Decision (arg1, arg2) {
  var decision, choices;

  if (!(this instanceof Decision)) {
    throw new SyntaxError('Constructor must be called with the new operator');
  }

  if (typeof arg1 === 'function') {
    decision = arg1;
    choices = arg2;
  }
  else {
    decision = null;
    choices = arg1;
  }

  if (decision) {
    if (typeof decision !== 'function') {
      throw new TypeError('Parameter decision must be a function');
    }
  }
  else {
    decision = function (message, context) {
      return message;
    }
  }

  if (choices && (typeof choices === 'function')) {
    throw new TypeError('Parameter choices must be an object');
  }

  this.decision = decision;
  this.choices = {};

  // append all choices
  if (choices) {
    var me = this;
    Object.keys(choices).forEach(function (id) {
      me.addChoice(id, choices[id]);
    });
  }
}
function Decision ( arg1 , arg2 ) { var decision , choices ; if ( ! ( this instanceof Decision ) ) { throw new SyntaxError ( 'Constructor must be called with the new operator' ) ; } if ( typeof arg1 === 'function' ) { decision = arg1 ; choices = arg2 ; } else { decision = null ; choices = arg1 ; } if ( decision ) { if ( typeof decision !== 'function' ) { throw new TypeError ( 'Parameter decision must be a function' ) ; } } else { decision = function ( message , context ) { return message ; } } if ( choices && ( typeof choices === 'function' ) ) { throw new TypeError ( 'Parameter choices must be an object' ) ; } this . decision = decision ; this . choices = { } ; // append all choices if ( choices ) { var me = this ; Object . keys ( choices ) . forEach ( function ( id ) { me . addChoice ( id , choices [ id ] ) ; } ) ; } }
extend Block with function then 
Decision
A decision is made by executing the provided callback function, which returns
a next control flow block.

Syntax:

new Decision(choices)
new Decision(decision, choices)

Where:

{Function | Object} [decision]
When a `decision` function is provided, the
function is invoked as decision(message, context),
where `message` is the output from the previous
block in the chain, and `context` is an object
where state can be stored during a conversation.
The function must return the id for the next
block in the control flow, which must be
available in the provided `choices`.
If `decision` is not provided, the next block
will be mapped directly from the message.
{Object.<String, Block>} choices
A map with the possible next blocks in the flow
The next block is selected by the id returned
by the decision function.

There is one special id for choices: 'default'. This id is called when either
the decision function returns an id which does not match any of the available
choices.

@param arg1
@param arg2
@constructor
@extends {Block}
extend Block with function then Decision A decision is made by executing the provided callback function which returns a next control flow block .