custom functions with complex param not working
arvindzen opened this issue · 0 comments
arvindzen commented
Hello,
Thank you for the great library. I added a custom function with complex params. when the function is applied, it throws an error 'throw new Error("Unrecognized operation " + op );'
Example below:
var a = {val: 1};
var b = {val: 2};
//this works
var plus = function(a,b){ return a+b; };
jsonLogic.add_operation("plus", plus);
jsonLogic.apply({"plus":[a.val, b.val ]});
//THIS THROWS ERROR
var objectPlus = function(a,b){ return a.val+b.val; };
jsonLogic.add_operation("objectPlus", objectPlus);
jsonLogic.apply({"objectPlus":[a, b]});
I will also add that a complex single param works.
//this works too
var operands = {a : {val: 1},b : {val: 2}} ;
var objectPlusSingleParam = function(op){ return op.a.val + op.b.val; };
jsonLogic.add_operation("objectPlusSingleParam", objectPlusSingleParam);
jsonLogic.apply({"objectPlusSingleParam": [operands] });