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

Component sendAction doesn't handle attrs. + action correctly #11176

Closed
jnhuynh opened this issue May 15, 2015 · 8 comments
Closed

Component sendAction doesn't handle attrs. + action correctly #11176

jnhuynh opened this issue May 15, 2015 · 8 comments
Labels
Milestone

Comments

@jnhuynh
Copy link

jnhuynh commented May 15, 2015

I pass a route action name string to a component. That component will send that action when one of it's own actions is triggered. Refer to the example below.

// In my route's template
{{some-component specialAction='NameOfActionInMyRoute'}}
// components/some-component.js
...
actions: {
  rightButtonClick: function() {
     this.sendAction('specialAction');
  }
}
...

// Template
<button {{action 'rightButtonClick'}}>
  Mr. Right Button
</button>

Given the below implementation in Ember.1.13.0-Beta-1:

 sendAction: function (action) {

      ...

      // Send the default action
      if (action === undefined) {
        ...
      } else {
        actionName = property_get.get(this, "attrs." + action) || property_get.get(this, action);
        Ember['default'].assert("The " + action + " action was triggered on the component " + this.toString() + ", but the action name (" + actionName + ") was not a string.", isNone['default'](actionName) || typeof actionName === "string" || typeof actionName === "function");
      }

property_get.get(this, "attrs." + action) will return an object of the following format:

Object {
  value: "NameOfActionInMyRoute",
  update: function,
  MUTABLE_CELL [id=__ember1431709265242204799127239]: true
}

Since the result is an Object it fails the assertion.

We can extract the value by changing the actionName assignment to:

actionName = property_get.get(this, "attrs." + action + ".value") || property_get.get(this, action);

That's just a suggestion though, I'm not sure of the implications of the change.

@jnhuynh
Copy link
Author

jnhuynh commented May 15, 2015

I reverted to Ember 1.12.0. Bug is gone. The implementation for sendAction is different of course.

@rwjblue rwjblue changed the title [BUG] [Ember 1.13.0-Beta-1] Component sendAction doesn't handle attrs. + action correctly Component sendAction doesn't handle attrs. + action correctly May 15, 2015
@rwjblue
Copy link
Member

rwjblue commented May 15, 2015

I attempted to replicate the scenario you described in this JSBin, but it properly triggers the route action.

@rwjblue
Copy link
Member

rwjblue commented May 15, 2015

Ahh, so it appears that you are not passing the action name down as a string in the template, but rather as a bound property that resolves to a string (like {{some-thing action=somePropertyHere}}). This is definitely triggering a bug in the sendAction code.

Demo: http://emberjs.jsbin.com/rwjblue/508/edit

@rwjblue rwjblue added the Bug label May 15, 2015
@rwjblue rwjblue added this to the 1.13.0 milestone May 15, 2015
@oskarrough
Copy link

Possibly related, I can't send actions to components since 1.13-beta.1: http://stackoverflow.com/questions/30274097/sending-actions-to-a-component-with-ember-js-1-13?noredirect=1#comment48650708_30274097 (isolated test cases included)

@mixonic
Copy link
Sponsor Member

mixonic commented May 16, 2015

Working through this now, I'll have a fix in an hour or two

mixonic added a commit that referenced this issue May 16, 2015
[BUGFIX beta] Handle mut cell action names. Fixes #11176
@oskarrough
Copy link

@mixonic thanks a lot. Assuming the bugs are/were related I tried it out but no dice with the testcase here: http://jsbin.com/gohovifedi/2/edit

Any ideas?

@mixonic
Copy link
Sponsor Member

mixonic commented May 17, 2015

@oskarrough this issue was completely unrelated to #11192.

@jnhuynh
Copy link
Author

jnhuynh commented May 18, 2015

@mixonic and @rwjblue Thanks for fixing this!

mixonic added a commit that referenced this issue May 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants