Serabe / ember-bind-helper

Add a bind helper to bind a function to a context

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

{{bind}} doesn't work with @arg objects

gossi opened this issue · comments

Hey,

looks like your {{bind}} helper is what the {{action}} helper should be and is the way to go, especially with sparkles and glimmer components. I made a test-case to see how future-proof it is. You can find the whole test case here: https://github.com/gossi/sparkles-test/

I found one problem while I was researching: It cannot handle @arg properly. This does not work:

{{! src/ui/routes/application/template.hbs }}

<MyComponent @parent={{this}} />
import Controller from '@ember/controller';

export default class ApplicationController extends Controller {
  whoAmI() {
    console.log('whoami', this instanceof ApplicationController, this);
  }
}

This does not work:

{{! src/ui/components/my-component/template.hbs }}

<button onclick={{bind @parent.whoAmI}}>Who Am I?</button>

This works:

{{! src/ui/components/my-component/template.hbs }}

<button onclick={{bind @parent.whoAmI target=@parent}}>Who Am I?</button>

(In my test these are the components bind-object-context and bind-object-context-with-target)

From my far point of view, I'd say, it doesn't work correctly with @arg objects.

I'll check tonight or tomorrow morning. Should be easy to fix. Let's hope I'm not wrong :P

I'll do the release these weekend. Thank you for your issue!

Awesome. Please ping here, so I can test my suite against the new release. Thank you so much :)

Wonderful. My test project is working showing green results all over the place :)