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

Added universal expressions (short form functions): $ex #232

Merged
merged 3 commits into from
Feb 4, 2023

Conversation

dbuezas
Copy link
Owner

@dbuezas dbuezas commented Feb 3, 2023

$fn ({getFromConfig, xs, ...etc...}) => getFromConfig("title")
equivalent to
$f get("title")

(all other params also available)

@dbuezas
Copy link
Owner Author

dbuezas commented Feb 3, 2023

What do you think about this?

  • $fn is very explicit and easy to understand, but I find it too verbose. Having to state the parameters and whatnot is redundant.
  • I'm considering this short form $f, that automatically adds this prelude:
    ({ getFromConfig, get, hass, vars, path, css_vars, xs, ys, statistics, states, meta })=>
  • and also get is an alias of getFromConfig

I think that it's good to keep $fn not only to avoid further breaking changes, but also because it explains $f in a sense.

@FrnchFrgg @zanna-37 you've both been very critical and constructive, I'd really appreciate your opinions&thoughts on this

@dbuezas
Copy link
Owner Author

dbuezas commented Feb 3, 2023

Here's the skynet's opinion:
image
image

$expr and $ex are really not bad. (I'll hold my urge to pick$jsex)

@dbuezas
Copy link
Owner Author

dbuezas commented Feb 4, 2023

I used this a bit today and it is quite convenient, but I'll rename it to $ex, a "universal expression".

@dbuezas dbuezas changed the title Added short form functions: $f Added universal expressions (short form functions): $ex Feb 4, 2023
@dbuezas dbuezas marked this pull request as ready for review February 4, 2023 18:52
@dbuezas dbuezas merged commit 2c324ca into master Feb 4, 2023
@FrnchFrgg
Copy link
Contributor

Indeed, something like $ex or $expr is what I would recommend, since it corresponds to the expression part of a lambda function. I slightly prefer the longer form, but not much.

if (typeof value === "string" && value.startsWith("$fn")) {
value = myEval(value.slice(3));
if (typeof value === "string") {
if (typeof value === "string" && value.startsWith("$ex")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you check again for the type of value ?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be extra sure?
Thanks, I fixed that now.

@dbuezas
Copy link
Owner Author

dbuezas commented Feb 5, 2023

I slightly prefer the longer form, but not much.

I went with $ex partly to keep it short, but mostly because $fn also had 2 letters. I've been using it and it is quite convenient :)

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

Successfully merging this pull request may close these issues.

None yet

2 participants