Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom functions with complex param not working #26

Open
arvindzen opened this issue Dec 18, 2020 · 0 comments
Open

custom functions with complex param not working #26

arvindzen opened this issue Dec 18, 2020 · 0 comments

Comments

@arvindzen
Copy link

arvindzen commented Dec 18, 2020

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] });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant