Skip to content

url-for helper#92

Closed
GavinJoyce wants to merge 1 commit intoemberjs:masterfrom
GavinJoyce:gj/href-to
Closed

url-for helper#92
GavinJoyce wants to merge 1 commit intoemberjs:masterfrom
GavinJoyce:gj/href-to

Conversation

@GavinJoyce
Copy link
Member

@rwjblue
Copy link
Member

rwjblue commented Sep 13, 2015

👍 - I personally prefer 'url-for' (because this is useful for more things than just hrefs).

I'd also like to see a 'url-is-active' helper for similar reasons (it could fit in this RFC, but I'm fine with it being a separate one also).

@rwjblue
Copy link
Member

rwjblue commented Sep 13, 2015

Also, I'd like to see Ember.LinkComponent be changed around to provide all of its functionality via public template helpers (possibly when it is implemented as a glimmer component). This 'url-for'/'href-to' helper is a great start towards that goal...

@GavinJoyce
Copy link
Member Author

Thanks, I agree that url-for is a better name. I'd be happy to roll in url-is-active into this RFC too, they are very much related

Copy link
Member

Choose a reason for hiding this comment

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

wouldn't the solution to ^ be to make link-to not slow? This seems like it would have a much greater impact.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, the faster that link-to is, the less our need for something like this. We've found the href-to addon to be 6-12x times faster in Ember 1.11-1.13 though. link-to will always have much more to do, all href-to has to do is to generate a URL.

Copy link
Member

Choose a reason for hiding this comment

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

We should definitely make link-to faster, but the two ideas are not opposed to each other. For example, one way to make it faster is to have it take advantage of template helpers like this one.

Copy link
Member

Choose a reason for hiding this comment

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

my point was, we don't normally except joe turbo features, when the core primitive is still more or less unoptimized. So that being a primary motivation may give the wrong impression.

As i mentioned, the more compelling motivation should be to de-sugar link-to, this will:

  • prevent link-to from continuing to be a junk drawer
  • allow us to use new templating features to make the component parts faster (but they should also then in-tern make link-to better/faster)
  • enable more experimentation

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll rewrite the motivation section to emphasise these points. Thanks

@stefanpenner
Copy link
Member

I suspect a sibling RFC (or maybe part of this one) should explore the extracting other parts of link to. Such as the classes that are associated with a URL. active/loading/current etc. The reason i suggest this, is to ensure a uniform experience between the component parts.

With that in-place, link-to may easily just become a sugaring of its component parts. It could even become just an HTMLBars transform, with nearly no overhead. All while exposing the building blocks as public api.

@GavinJoyce
Copy link
Member Author

I've renamed the helper to url-for and rewrote the motivations sections to better capture both your suggestions:

Decomposing `link-to` into a set of helpers will allow us to simplify its internals
while providing new low level primitives for use in performance sensitive 
applications. `url-for`, the first of these extracted helpers, will allow for simple 
URL rendering in an Ember application. Extracting separate helpers for dealing 
with link classes will be suggested in a future RFC.

This proposal would also allow plain URLs to be used within an Ember application 
without triggering an application reload. For example, a url such as `/about` 
could be used within a template or helper.

In order to keep it small, I've kept this focused on url-for. The other class helpers can follow once we've got agreement on this one.

@GavinJoyce GavinJoyce changed the title RFC for href-to helper RFC for url-for helper Sep 13, 2015
Copy link
Member

Choose a reason for hiding this comment

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

Slight nit-pick: I personally wouldn't call this a relative url since it includes a leading slash.

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks

@stefanpenner
Copy link
Member

The other class helpers can follow once we've got agreement on this one.

👍

@tomdale
Copy link
Member

tomdale commented Sep 14, 2015

Awesome first step. My feeling is that this functionality should likely be specced out as part of a routing service, and the url-for helper should just be a small wrapper exposing that to Handlebars-land. Perhaps the first iteration of the public routing service just exposes urlFor and transitionTo methods and we can build from there.

@GavinJoyce GavinJoyce changed the title RFC for url-for helper url-for helper Sep 16, 2015
@chadhietala
Copy link
Contributor

This will make links within i18n strings much easier so 👍 . For example we use a i18n string format based on Java xmsg (Yahoo uses something similar but standardized) and our helper looks something like.

<!-- define the string -->
{{t-def 'hello_world' text='Hello {Hello :name, click this <a href={:link}>Link</a>'}}

<!-- Use string -->
<h1>{{t 'hello_world' name=name link=(url-for 'profile' 123) }}</h1>

Definitely a need for this type of primitive.

@MiguelMadero
Copy link

I was thinking the same. Let's build on top of the routingService.

@Turbo87
Copy link
Member

Turbo87 commented Jul 6, 2016

has there been any progress on this? I need a similar solution to what @chadhietala described and it would be awesome if ember would provide this out of the box.

@rwjblue
Copy link
Member

rwjblue commented Oct 14, 2016

Closing this in favor of #95.

Thanks for opening @GavinJoyce, hoping to land the router service RFC which should include this helper soon.

@rwjblue rwjblue closed this Oct 14, 2016
@GavinJoyce GavinJoyce deleted the gj/href-to branch November 7, 2016 20:18
kategengler pushed a commit that referenced this pull request Jan 19, 2019
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.

7 participants