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

action() Factory #28

Merged
merged 5 commits into from
Sep 9, 2023
Merged

action() Factory #28

merged 5 commits into from
Sep 9, 2023

Conversation

gossi
Copy link
Owner

@gossi gossi commented Sep 5, 2023

Testing some APIs

Comment on lines 33 to 52
// Invocation Styles:
//
// 1. (action)
//
// - `<button {{on "click" (incOne)}}>Inc</button>`
// - `<button {{on "click" (inc 10)}}>Inc</button>`
// - `<Step @inc={{10}} @push={{(inc)}}>Inc</Step>`
//
// 2. (fn (action))
//
// - `<button {{on "click" (fn (incOne))}}>Inc</button>`
// - `<button {{on "click" (fn (inc 10))}}>Inc</button>`
// - `<button {{on "click" (fn (inc) 10)}}>Inc</button>`
// - `<Step @inc={{10}} @push={{(fn (inc))}}>Inc</Step>`
//
// 3. (command action)
//
// - `<button {{on "click" (command incOne)}}>Inc</button>`
// - `<button {{on "click" (command (inc 10))}}>Inc</button>`
// - `<Step @inc={{10}} @push={{command inc}}>Inc</Step>`
Copy link
Owner Author

Choose a reason for hiding this comment

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

These are some API Design ideas. Please give your feedback.

They are declarative so far, but I think, they can be turned imperative, too - somewhat around these lines:

// ---
const add = action(({ services }) =>
  (a: number, b: number) => services.adder.add(a, b)
);

const doAdd = add(owner);
doAdd(3, 5);

const addOne = (b: number) => doAdd(1, b);
addOne(5);

so basically, action() returns a factory, than the final function itself - is there a known way around this? 😇

Choose a reason for hiding this comment

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

how else would you get the owner in there? it's gotta be wired in from either the user, or the manager infra

Copy link
Owner Author

Choose a reason for hiding this comment

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

In my defense: The imperative API wasn't there from the start at all. I only focused on the declarative API as its main citizen, but realized, this can be done, too.

I'm less concerned about connecting it with the owner (that's as you said provided or manager infra).

What I'm most interested in (under the terms of what's possible given ember's API):
Does it "feel" good to be used or is it "clumsy"/stiff, rather than inviting to be used? (for both imperative and declarative API)

@gossi gossi marked this pull request as ready for review September 7, 2023 18:51
@gossi gossi added the enhancement New feature or request label Sep 7, 2023
@gossi gossi changed the title action() Wrapper action() Factory Sep 7, 2023
@gossi gossi merged commit eea9058 into main Sep 9, 2023
@gossi gossi deleted the action-wrapper branch September 9, 2023 15:51
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

Successfully merging this pull request may close these issues.

2 participants