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

Add constants #38

Closed
Tracked by #49
cshaa opened this issue Jun 17, 2021 · 0 comments
Closed
Tracked by #49

Add constants #38

cshaa opened this issue Jun 17, 2021 · 0 comments
Labels
enhancement New feature or request implemented This feature is implemented in `develop` and ready for testing
Milestone

Comments

@cshaa
Copy link
Owner

cshaa commented Jun 17, 2021

Sometimes, it is necessary to provide various constants to the user. Right now, the only way to achieve this is to modify the data, which is rather unfortunate – it would be much better to specify the constants only once at compile time. Example usage:

const options = {
  constants: { pi: Math.PI }
}
const fn = compileExpression(`2 * pi * radius`, options)

fn({ radius: 1/2 })
// → Math.PI

It should be possible to access data fields shadowed by constants using single-quoted symbols:

const options = { constants: { a: "a_const " } }
const data = { a: "a_data ", b: "b_data " }

// single-quotes give access to data
const expr = `'a' + a + 'b' + b`

compileExpression(expr, options)(data)
// → "a_data a_const b_data b_data"

In order to keep the API simple, constants will bypass a customProp function – if a developer wants total control over the identifiers, they shouldn't define any constants.

@cshaa cshaa added the enhancement New feature or request label Jun 17, 2021
@cshaa cshaa added this to the v3 milestone Jun 17, 2021
cshaa added a commit that referenced this issue Sep 21, 2021
@cshaa cshaa added the implemented This feature is implemented in `develop` and ready for testing label Sep 21, 2021
@cshaa cshaa closed this as completed Sep 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request implemented This feature is implemented in `develop` and ready for testing
Projects
None yet
Development

No branches or pull requests

1 participant