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

Allow signal options in the @signal decorator #42

Open
justinfagnani opened this issue Apr 15, 2024 · 3 comments · May be fixed by #55
Open

Allow signal options in the @signal decorator #42

justinfagnani opened this issue Apr 15, 2024 · 3 comments · May be fixed by #55

Comments

@justinfagnani
Copy link
Contributor

justinfagnani commented Apr 15, 2024

@signal is a wrapper for new Signal.State() but it does not expose the options argument.

It should be possible to do:

class MyClass {
  @signal({equals: deepEquals})
  accessor someImmutableThing;
}

There would be two options for the signal() signature:

  1. @signal accessor foo for non-options usage and @signal({...}) accessor foo for options usage.
  2. @signal() accessor foo for non-options usage and @signal({...}) accessor foo for options usage.

(2) is possible by duck-typing the arguments.

I personally prefer style (2) for consistency, but there's also consistency to consider with the other decorators. I guess @cached could accept options as well, since it's basically a wrapper for new Signal.Computed().

@NullVoxPopuli
Copy link
Collaborator

Option 1 is my preference as well with decorators, prevents usneeded function execution in the simple (usually more common) case.

@cached could accept options as well

Sounds like a good idea!

@justinfagnani
Copy link
Contributor Author

Oops... I meant to say that I prefer option (2)! I found that a lot of decorators take options, so always having the () after the decorator provides visual consistency. It also makes it easier to add options in the future even if a decorator doesn't take them now.

@NullVoxPopuli
Copy link
Collaborator

There is no reason both can't be supported simultaneously, as it turns out. Invocation without options is just {} for options.

But i do think this should be avoided for faster module evaluation

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 a pull request may close this issue.

2 participants