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

Support JSON defined rules import #39

Closed
eisenivan opened this issue May 4, 2020 · 5 comments
Closed

Support JSON defined rules import #39

eisenivan opened this issue May 4, 2020 · 5 comments
Assignees

Comments

@eisenivan
Copy link
Contributor

eisenivan commented May 4, 2020

Basically this feature is to allow the importing of a JSON defined rules structure (similar to regent < 3.x.x

{
  isHot: { greaterThan: ['@temperature', 55]  },
  isRaining: { equals: ['@precipitation', 'raining'] },
  windyAndCold: {
    or: [
      { greaterThan: ['@windSpeed', 10] },
      { lessThan: ['@temp', 65] }
    ]
  }
}

We could call regent.import on this rules object and the method would return an object of rules, with the value of each being a regent function. I propose that the first iteration of this not try to handle custom predicates. I can't think of a sane way to do that.

@eisenivan eisenivan self-assigned this May 5, 2020
@eisenivan
Copy link
Contributor Author

Here is a PR with code the handle JSON imports.

#40

No docs written yet, but if anyone has any feedback on the API let me know.

@jesselee34
Copy link
Contributor

What about just regent.import(json, predicates)

@jesselee34
Copy link
Contributor

Also, is this useful without a way to export as well?

@eisenivan
Copy link
Contributor Author

@jesselee34 I think it's super useful without export. You could define a rules server that served rules to multiple applications.

@eisenivan
Copy link
Contributor Author

eisenivan commented May 6, 2020

I don't like regent import because import is a reserved keyword, so you couldn't do

import { import } from 'regent'

And I don't want to have to do this every time

import { import as importFn} from 'regent'

Plus, the parse function doesn't really import anything, it returns an object of regent functions

eisenivan added a commit that referenced this issue May 8, 2020
eisenivan added a commit that referenced this issue May 12, 2020
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

2 participants