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

Call route-action logic inside a route or mixin. #52

Open
viniciussbs opened this issue Feb 17, 2017 · 1 comment
Open

Call route-action logic inside a route or mixin. #52

viniciussbs opened this issue Feb 17, 2017 · 1 comment

Comments

@viniciussbs
Copy link

Hi.

Inside my app a use component helper to dynamically call a component. But the attributes may vary depending of which component I'm calling.

Let's say I have this code:

{{#if isUserModal}}
  {{modal/user-modal user=model like=(route-action "like")}}
{{else if isEventModal}}
  {{modal/event-modal event=model like=(route-action "like") join=(route-action "join")}}
{{/if}}

I would like to write it this way:

{{component componentName modalModel=model modalActions=modalActions}}

In this case, modalActions is a hash with the actions. But, to do this, I need a way to use route-action logic inside a mixin. The changeset helper uses internally a Changetset class that can be used anywhere. It would be great to have a RouteAction class, too.

@lolmaus
Copy link

lolmaus commented May 7, 2017

When you use the component helper, your polymorphic components must have identical arguments.

In your example, you have to refactor user=model and event=model into a common name: modalModel.

But if some of the components needs a unique argument, you'll be passing it as usual, e. g. eventGroup=eventGroup. A user modal would simply ignore that argument.

You already know that. So why don't you apply the same principle to actions? Use common names for shared actions, use unique names for non-shared actions.

In this example I've separated shared attributes and actions from unique attributes and actions:

{{component componentName
  modalModel   = model
  like         = (route-action "like")

  eventGroup   = eventGroup
  joinEvent    = (route-action "join")
}}

This approach does not require making such changes to ember-route-action-helper that are unlikely to be used by anyone else.

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

No branches or pull requests

2 participants