feat: bind this context to owner#132
Conversation
|
|
||
| this.setProperties({ lookup, testIdentifier }); | ||
|
|
||
| await render(hbs`{{get (this.lookup this.testIdentifier) "string"}}`); |
There was a problem hiding this comment.
the intent is solid, but ultimately we need the VM to see property.path (when used in the invocation position), to do path.apply(property, args)
this way we get correctly bound functions on all objects.
like, XState interpreters, window globals, services, etc
There was a problem hiding this comment.
Yep! I've touched on that in my most recent comment in the RFC: emberjs/rfcs#756 (comment)
I also suggested not using the owner, but the invoking template context. I'd be very interested in your opinion on that.
There was a problem hiding this comment.
yeah, that would make sense to me.
the owner shouldn't get any special treatment with functions, but your functions should have whatever this you expect them to have.
so if your function needs the owner, you getOwner(this) in it.
but if your function is not defined in a place where this has an owner`, you won't get an owner.
function outerFunction() {
getOwner(this);
}
class extends Component {
// can access owner
myFunction = () => {
let owner = getOwner(this);
}
outerFunction = outerFunction; // no owner
boundOuterFunction = outerFunction.bind(this); // has owner
}
This PR binds
thisin functions invoked as a helper to the owner. I've suggested this behavior in emberjs/rfcs#756 (comment) and wanted to show a very rudimentary PoC.