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

[Feature request] Allow setting multiple keys #9

Open
boris-petrov opened this issue Oct 18, 2019 · 5 comments
Open

[Feature request] Allow setting multiple keys #9

boris-petrov opened this issue Oct 18, 2019 · 5 comments
Labels
enhancement New feature or request

Comments

@boris-petrov
Copy link
Contributor

We have a few actions in our codebase that do only a setProperties call which could use that set helper but it accepts only one key and value. Perhaps another helper for multiple ones could be written? Or the same one to be extended to allow multiple keys?

@pzuraq
Copy link
Collaborator

pzuraq commented Oct 18, 2019

Can you provide an example of the API that you're thinking about? Definitely interested, but I'm not sure what the ergonomics would be like.

@boris-petrov
Copy link
Contributor Author

@pzuraq - well, I haven't really thought about it, but I would guess something like:

<button {{on "click" (set-properties (array (key=this.greeting value="Hello!") (key=this.other value="bar!")))}}>

Or something. Another way would be to create a "chain" helper that would allow you to:

<button {{on "click" (chain (set this.greeting "Hello!") (set this.other "bar!"))}}>

Although this is not exactly the same because it will call set multiple times which is different from setProperties.

I guess there could be other ways of implementing this as well.

@alexlafroscia
Copy link
Member

That chain helper already exists as the queue helper from ember-composable-helpers

https://github.com/DockYard/ember-composable-helpers#queue

You should able to do this:

<button {{on "click" (queue (set this.greeting "Hello!") (set this.other "bar!"))}}>

Or even this

<input {{on "input" (queue (set this.greeting (get _ 'target.value')) (set this.other (get _ 'target.value')))}}>

@boris-petrov
Copy link
Contributor Author

@alexlafroscia - true, but there's two issues with that - 1) I have to install yet another addon; 2) the problem that I've mentioned in my previous comment - it will call set multiple times which is different from setProperties. Not ideal.

@pzuraq
Copy link
Collaborator

pzuraq commented Jul 11, 2020

I believe setProperties under the hood just calls set multiple times, there isn't really a difference these days. There may have been in the past with observer/chains suspension, but that's not the case with the recent autotracking refactors.

FWIW, I'm about to merge a refactor to replace the main API here with the one from ember-simple-set-helper, and going to release a new major version. The recommendation for picking values from events (e.g. the event.target.value for inputs) is going to be using {{pick}} from ember-composable-helpers, so it may make sense to use it together with this helper for more than one reason.

That said, I'm still open to adding something like this, but would need to think on the API a bit more to see if it would be worth it from an ergonomics perspective.

@alexlafroscia alexlafroscia added the enhancement New feature or request label Jul 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants