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

remove implicit dependencies on jQuery #55

Merged
merged 2 commits into from May 6, 2019

Conversation

0xadada
Copy link
Contributor

@0xadada 0xadada commented May 5, 2019

Remove jquery

For apps that explicitly remove their dependency on jQuery, this addon will break because it
imports from jquery assuming the consuming app already has it.

jQuery is imported in the component, but no dependency is declared in
the package.json. This works because until recently, jQuery was
available packaged with Ember source.

Ember RFC 0386
propses to remove jQuery eventually, and Ember already ships with the
@ember/jquery package installed directly as part of the "ember new"
output for new ember apps.

related to #54

Remove ember-ajax

I also removed the dependency on ember-ajax since we no longer need this as well.

Whitespace/formatting

You'll notice whitespace & formatting fixes, these are autofixes from ESLint.

For apps that explicitly remove their dependency on jQuery, this addon will break because it
imports from jquery assuming the consuming app already has it.

jQuery is imported in the component, but no dependency is declared in
the package.json. This works because until recently, jQuery was
available packaged with Ember source.

[Ember RFC 0386](https://emberjs.github.io/rfcs/0386-remove-jquery.html)
propses to remove jQuery eventually, and Ember already ships with the
@ember/jquery package installed directly as part of the "ember new"
output for new ember apps.

related to oskarrough#54
@0xadada 0xadada mentioned this pull request May 5, 2019
6 tasks
@@ -1,15 +1,19 @@
/* global YT, window */

import $ from 'jquery';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

byebye

});
},

didInsertElement() {
this._super(...arguments);

this.progressBarClick();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed


// clear the timer
this.stopTimer();

// remove progress bar click handler

this.removeProgressBarClickHandler();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

here i remove the manual click handler event binding.

@@ -137,21 +145,25 @@ export default Component.extend({
// If already loaded, make sure not to load the script again.
resolve(window.YT);
} else {
$.getScript('https://www.youtube.com/iframe_api');
let ytScript = document.createElement("script");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

since ember-ajax and jquery have been removed, $.getScript has been replaced with a native solution borrowed from jQuery.

Under the hood, all jQuery getScript was doing was creating a <script> tag and appending it to the page, thus evaluating the script on page. Here I just do that in 3 lines of code.

@@ -325,59 +341,73 @@ export default Component.extend({

// OK, this is stupid but couldn't access the "event" inside
// an ember action so here's a manual click handler instead.
progressBarClick() {
addProgressBarClickHandler() {
this.element.addEventListener(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

without jquery, i just use addEventListener instead of $().on(...).

let element = event.srcElement;
if (element.tagName.toLowerCase() !== "progress") return;
// get the x position of the click inside our progress el
let x = event.pageX - element.getBoundingClientRect().x;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replaced jquerys $(this).position().left with the commonly available getBoundingClientRect().x which is now standard across all browsers.

self.set("currentTime", clickedValue);
self.send("seekTo", clickedValue);
},
removeProgressBarClickHandler() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the event handler wasn't removed previously, so now it is cleaned up when the component is removed from the DOM.

@0xadada
Copy link
Contributor Author

0xadada commented May 5, 2019

@oskarrough i added some notes describing the changes I made. I hope you'll consider merging this PR as it'll allow Ember users who've removed jquery from their apps to consume your addon safely.

@0xadada
Copy link
Contributor Author

0xadada commented May 5, 2019

more on Ember removing jquery is here emberjs/rfcs#386

@0xadada
Copy link
Contributor Author

0xadada commented May 6, 2019

@oskarrough if you prefer, i can remove the noisy whitespace changes and limit the PR to just the logic changes 🙏

@oskarrough
Copy link
Owner

oskarrough commented May 6, 2019

Thanks so much again, also for the extra comments! Funny how it's now a thing to remove jQuery. Back in the days… if you were really cool you'd have at least three versions of jQuery on the same page ;)

Do you mind reverting the ' to " conversion? Or configuring eslint to not change that part?

Happy to merge in any case.

@0xadada
Copy link
Contributor Author

0xadada commented May 6, 2019

@oskarrough all set, travis is running now.

@oskarrough oskarrough merged commit cc4878f into oskarrough:master May 6, 2019
@oskarrough
Copy link
Owner

released as 0.9.5 🎂

@0xadada 0xadada deleted the remove-jquery branch May 6, 2019 18:31
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.

None yet

2 participants