How to use the krl-stdlib/types.isAction function in krl-stdlib

To help you get started, we’ve selected a few krl-stdlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Picolab / pico-engine / packages / pico-engine-core / src / runAction.js View on Github external
module.exports = async function runAction (ctx, domain, id, args, setting) {
  var returns = []
  if (domain) {
    var modAction = await ctx.modules.get(ctx, domain, id)
    if (!ktypes.isAction(modAction)) {
      throw new Error('`' + domain + ':' + id + '` is not an action')
    }
    returns = await modAction(ctx, args)
  } else if (id === 'noop') {
    returns = []// returns nothing
  } else if (ctx.scope.has(id)) {
    var definedAction = ctx.scope.get(id)
    if (!ktypes.isAction(definedAction)) {
      throw new Error('`' + id + '` is not defined as an action')
    }
    returns = await definedAction(ctx, args)
  } else if (id === 'send_directive' || id === 'sendDirective') {
    returns = await sendDirective(ctx, args)
  } else {
    throw new Error('`' + id + '` is not defined')
  }
  _.each(setting, function (id, i) {
    var val = returns[i]
    if (val === void 0 || _.isNaN(val)) {
      val = null
    }
    ctx.scope.set(id, val)
  })
}
github Picolab / pico-engine / packages / pico-engine-core / src / runAction.js View on Github external
module.exports = async function runAction (ctx, domain, id, args, setting) {
  var returns = []
  if (domain) {
    var modAction = await ctx.modules.get(ctx, domain, id)
    if (!ktypes.isAction(modAction)) {
      throw new Error('`' + domain + ':' + id + '` is not an action')
    }
    returns = await modAction(ctx, args)
  } else if (id === 'noop') {
    returns = []// returns nothing
  } else if (ctx.scope.has(id)) {
    var definedAction = ctx.scope.get(id)
    if (!ktypes.isAction(definedAction)) {
      throw new Error('`' + id + '` is not defined as an action')
    }
    returns = await definedAction(ctx, args)
  } else if (id === 'send_directive' || id === 'sendDirective') {
    returns = await sendDirective(ctx, args)
  } else {
    throw new Error('`' + id + '` is not defined')
  }
github Picolab / pico-engine / packages / node-pico-engine-core / src / runAction.js View on Github external
module.exports = cocb.wrap(function*(ctx, domain, id, args, setting){
    var returns = [];
    if(domain){
        returns = yield ctx.modules.action(ctx, domain, id, args);
    }else if(id === "noop"){
        returns = [];//returns nothing
    }else if(ctx.scope.has(id)){
        var definedAction = ctx.scope.get(id);
        if( ! ktypes.isAction(definedAction)){
            throw new Error("`" + id + "` is not defined as an action");
        }
        returns = yield definedAction(ctx, args);
    }else if(id === "send_directive" || id === "sendDirective"){
        returns = [
            //returns only one value
            yield send_directive(ctx, args)
        ];
    }else{
        throw new Error("`" + id + "` is not defined");
    }
    _.each(setting, function(id, i){
        var val = returns[i];
        if(val === void 0 || _.isNaN(val)){
            val = null;
        }
github Picolab / pico-engine / packages / pico-engine-core / src / index.js View on Github external
var applyFn = cocb.wrap(function*(fn, ctx, args){
    if(ktypes.isAction(fn)){
        throw new Error("actions can only be called in the rule action block");
    }
    if( ! ktypes.isFunction(fn)){
        throw new Error("Not a function");
    }
    return yield fn(ctx, args);
});
github Picolab / pico-engine / packages / pico-engine-core / src / index.js View on Github external
var applyFn = cocb.wrap(function*(fn, ctx, args){
    if(ktypes.isAction(fn)){
        throw new Error("actions can only be called in the rule action block");
    }
    if( ! ktypes.isFunction(fn)){
        throw new Error("Not a function");
    }
    return yield fn(ctx, args);
});