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

Replace jquery-params with URL API and authorize undefined action name #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GreatWizard
Copy link

@GreatWizard GreatWizard commented Apr 30, 2020

Following #53


Hello,

This PR is here to be able to used unamed action :)

And I take a look into buildUrl mixin to replace jquery-params by the native URL API.
There is a polyfills for old browser thanks to ember-url (because URL polyfills is not handle by babel).

ping @sandstrom

let pathUrl = url.charAt(url.length - 1) === '/' ? `${url}${path}` : `${url}/${path}`;

return query ? `${pathUrl}?${query}` : pathUrl;
let urlObj = new URL(url, 'https://example.com');
Copy link
Member

Choose a reason for hiding this comment

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

What if the url is absolute? Previously this function always returned absolute URL, while now its relative.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps I'm the one who led us down the wrong path here, in my previous comment.

If url is always absolute something like let urlObj = new URL(url); should work, along with return urlObj.toString();

Copy link
Author

Choose a reason for hiding this comment

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

I'm editing the PR in order to use native URL API only for queryParams and keep something more raw for the pathUrl to avoid conflict with absolute/relative URLs
Thanks for your feedbacks

@GreatWizard GreatWizard force-pushed the feat/ember-url branch 5 times, most recently from 8314cd7 to 44c8ada Compare May 6, 2020 15:53
Copy link
Contributor

@sandstrom sandstrom left a comment

Choose a reason for hiding this comment

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

Looks good!

@@ -1,8 +1,22 @@
import param from 'jquery-param';
import URL from 'url';
Copy link
Contributor

Choose a reason for hiding this comment

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

Could add a note about this being a polyfill and that when Ember drop support for IE 11 this won't be needed anymore:

https://caniuse.com/#search=URLSearchParams

}

// Use native URL API to generate query
let queryObj = new URL('https://exelord.com/ember-custom-actions/').searchParams;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let queryObj = new URL('https://exelord.com/ember-custom-actions/').searchParams;
// Passing in example.com because a domain is needed, but we're not using it.
// Using `URL` only to access the queryParams API.
let queryObj = new URL('https://example.com').searchParams;

Copy link
Member

@Exelord Exelord May 7, 2020

Choose a reason for hiding this comment

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

https://host.test - never use .com it fires DNS lookup, which allows track where the request is coming from.

Copy link
Author

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure? I'm 99% certain that new URL('https://example.com') won't fire any DNS lookups. It's just a bunch of string operations.

But yeah, .test should also work well.

Copy link
Member

Choose a reason for hiding this comment

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

In case we won't render it that's true. But just to prevent that issue in the future is better to forget about .com's for examples :)

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