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

Update actions to kebob case & arguments. #159

Merged
merged 4 commits into from
Oct 12, 2016
Merged

Conversation

Robdel12
Copy link
Collaborator

@Robdel12 Robdel12 commented Oct 7, 2016

Now we send the same arguments for all of the actions, they're kebob cased, and are closure actions.

@Robdel12 Robdel12 modified the milestone: v3.0.0 Oct 7, 2016
@Robdel12 Robdel12 force-pushed the fs/rename-actions branch 2 times, most recently from 8d4a05a to 9dcc22e Compare October 8, 2016 03:43
Copy link
Contributor

@cafreeman cafreeman left a comment

Choose a reason for hiding this comment

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

Left some in-line comments but overall I think this looks really good! Nice job standardizing the arguments across the board and updating the docs :)

// action body...
}
```

Most of the time all you need is the value that has been selected, but
sometimes your action requires more context than just that. In those
cases, you can associate arbitrary attributes with the component
itself and use them later inside your action handler. For example:
cases, you can use the `componentState` argument. It contains a couple
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a little confused about componentState thing. Should there be an actual argument to the component called componentState? In the example, I just see action and required

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, ok, I see now that componentState is a hash of potential arguments (like isRequired, isMultiple, etc.). Could we make it clearer that componentState isn't the actual component property that you'll be using, but is instead a componentState hash?

this.sendAction('action', nextValue, this);
this.sendAction('onchange', this, nextValue, event);
this.sendAction('action', nextValue, event, this.get('componentState'));
this._handleAction('on-change', nextValue, event);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this dispatch correctly? I'm concerned that bubbling an action with sendAction AND calling the closure action could just dispatch the action twice? Is sendAction a no-op if a closure action is passed in or something?

Now we send the same arguments for all of the actions. The value of the
select & the event.
@Robdel12 Robdel12 merged commit 815c40b into master Oct 12, 2016
let actionValue = this.get(action);

if(typeof actionValue === 'string') {
Ember.warn(`x-select: You must use the action helper for all actions. The try: ${action}=(action "${actionValue}") in your template`, false, {id: 'x-select-string-action'});
Copy link
Collaborator

Choose a reason for hiding this comment

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

"The try: "

Seems like a typo?

return;
}

this.get(action)(value, event);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the right track, but I think we can make it a bit clearer and improve the error handling even more.

  1. _handleAction isn't really what it's doing. It seems like it's dispatching the action so that something else can handle it. callAction, invokeAction, doAction would be better candidates.
  2. We issue a warning if actionValue is a string, but it if we're going to go to the effort of performing an explicit check on the type of the action value, then we should issue a warning if it's anything except a function. Because anything except a function will fail.
  3. If we've already got the action in the form of actionValue, then let's just call it:
actionValue(value, event);

@Robdel12 Robdel12 deleted the fs/rename-actions branch December 27, 2016 16:08
kjhangiani added a commit to soxhub/emberx-select-backup that referenced this pull request Dec 7, 2017
- see adopted-ember-addons#159
- change event names to kebab-case to smooth transition from 2.x to 3.x
- change argument order to match 3.x
- NOTE: last argument `component` is deprecated in 3.x
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.

3 participants