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

Functional differences between this and original JS port #18

Open
PeterLanglois opened this issue Feb 26, 2020 · 2 comments
Open

Functional differences between this and original JS port #18

PeterLanglois opened this issue Feb 26, 2020 · 2 comments

Comments

@PeterLanglois
Copy link

I've noticed that the operations in this port work entirely different then they do in the original JS port.
Specifically here:

return LAMBDAS[operator.to_s].call(interpolated, data) if is_standard?(operator)

JSONLogic is defined to accept the elements in an array as the argument to an operation.
However, your operations accept an array and the original data object.

With all the testing I've done so far, it seems like everything officially supported in the JS port works the same in this Ruby port.
Ex)

rule = {+: [1, 2]}
data = {}
JSONLogic.apply(rule, data) # 3

The result of this will be 3 in both ports ✅

However, if you were to define something like this in ruby:

rule = {+: [{var: 'data'}]}
data = {data: [1,2]}
JSONLogic.apply(rule, data) # 3

and in JS

rule = {"+": [{"var": "data"}]}
data = {"data": [1,2]}
jsonLogic.apply(rule, data) # 1

You end up with 3 in Ruby and 1 in JS. ❌

Ultimately this leads to inconsistencies when trying to develop cross-platform.

@bhgames
Copy link
Owner

bhgames commented Apr 18, 2020

Ok, thanks for letting me know! Feel free to submit a PR to fix this, I'd love to have it in. I'm pretty busy these days, so I don't get to dropin as often.

@chuckmitchell
Copy link

Could I suggest using https://github.com/rails/execjs on the server? That way you use the same JS port front and back end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants