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

[BUGFIX beta] bind all methods on the router service for use with fn … #20017

Closed

Conversation

NullVoxPopuli
Copy link
Contributor

@NullVoxPopuli NullVoxPopuli commented Mar 12, 2022

…and default helper manager

This PR is rebased off of #20018 so review that first

This resolves an issue where this code:

{{#if (this.router.isActive 'some.route')}}

Would lose the this binding.
Discovered here

This is only an issue since the:
emberjs/rfcs#756
(and https://github.com/NullVoxPopuli/ember-functions-as-helper-polyfill/)

Explanation here

but, I'm still upset that bound methods on classes aren't default 😅
anywho, I used @action here, idk if that's the right call since action does a bunch of other stuff, too.

I also noticed that the refresh method was still marked as canary.
refresh was declared as released in 4.1: https://blog.emberjs.com/ember-4-1-released/
so I removed the feature flag.

@NullVoxPopuli NullVoxPopuli force-pushed the bind-router-service-methods branch 2 times, most recently from e91d863 to e2decfd Compare March 12, 2022 15:30
NullVoxPopuli added a commit to NullVoxPopuli/limber that referenced this pull request Mar 12, 2022
NullVoxPopuli added a commit to NullVoxPopuli/limber that referenced this pull request Mar 12, 2022
@NullVoxPopuli
Copy link
Contributor Author

updated

@chriskrycho
Copy link
Contributor

chriskrycho commented Mar 25, 2022

@NullVoxPopuli mind rebasing now that #20018 is merged? That will help one of us review/land it!

@NullVoxPopuli
Copy link
Contributor Author

@chriskrycho done! 🎉

@chriskrycho
Copy link
Contributor

@NullVoxPopuli we talked about this at a Framework team meeting a few weeks ago but responding fell off of folks' radars because of the focus on EmberConf. Net, we want to solve this not by binding these but by making direct method invocation work correctly—in which case, the invocation you have here will “just work”, and importantly folks will be able to use any methods directly. An example I’ve used a few times lately that falls out of that is using methods like the relatively new Array.prototype.at:

interface Signature {
  Args: {
    names: string[];
    selectedIdx: number;
  };
}

<template type:signature={Signature}>
  <p>{{(names.at selectedIdx)}}</p>
</template>

(N.B. that specific syntax doesn't yet work; but something like it should soon.)

@NullVoxPopuli
Copy link
Contributor Author

So does that mean the approach needed is in the VM? ie, change it to do something like names.at.call(names, selectedIdx) ?

but then what happens when you only have a reference to at? with no way of knowing what the this is?

@chriskrycho
Copy link
Contributor

I mentioned this in Discord but copying it here for folks following the thread: the idea is to align it with JS. If you have the array, it works, otherwise you need to bind it—no different than in JS.

@chriskrycho
Copy link
Contributor

I put this on the agenda for today’s spec group meeting (spec group == breakout session from the Framework Team meeting, where we deep dive on technical details of things, which other relevant folks are invited to as makes sense!) so we can hopefully make some progress on it.

@chriskrycho
Copy link
Contributor

The second chunk of the notes from today's spec meeting notes covers the discussion on this!

@kategengler
Copy link
Member

Is this still relevant?

@NullVoxPopuli
Copy link
Contributor Author

NullVoxPopuli commented Dec 12, 2023

I think we're going to solve this in the VM though, and have functions auto-bound to their host object.

e.g.:

{{this.router.isActive "foo"}}
is roughly the same as

let isActive = this.router.isActive.bind(this.router);

isActive('foo');

which will be a better solve across all sorts of libraries

@NullVoxPopuli NullVoxPopuli deleted the bind-router-service-methods branch December 12, 2023 17:26
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