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

call functions with namespace #96

Open
seocochan opened this issue Dec 4, 2020 · 0 comments
Open

call functions with namespace #96

seocochan opened this issue Dec 4, 2020 · 0 comments

Comments

@seocochan
Copy link

seocochan commented Dec 4, 2020

Hi Tom

I'm currently working on implementing simple rules engines and considering jexl as a DSL to adopt.

I found out that some implementations like this provides calling methods with namespace(class names)

So I tried some expressions like FooService.doSomething() or FooService#doSomething()on jexl but it fails.

here is the code I tried on runkit

const jexl = require("jexl")

const input = {
  order: {
    total: 100000,
  },
  coupon: {
    status: 'ACTIVE'
  },
}

jexl.addFunction('OrderService.discountOrder', (order, rate) => order.total = order.total * (1.0 - rate))

const rules = [
  `OrderService.discountOrder(order, 0.2)`, // mutate passed object
]

const results = await Promise.all(rules.map(rule => jexl.eval(rule, input)))

console.log(results)
console.log(input.order)

I guess there're some reserved tokens like defined on grammar.js but is there any way to avoid these behavior or any suggestions to achieve my point?

Thanks.

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