mozillascience / software-discovery-dashboard

MIT License
19 stars 8 forks source link

Use of JQuery #38

Closed amb8805 closed 8 years ago

amb8805 commented 8 years ago

Is there any reason to avoid using JQuery? Especially for certain useful methods: after, eq, etc. It is already included as a dependency due to bootstrap therefore weight is already present in the system.

varzaman commented 8 years ago

I say using JQuery is fine if you find a good use for it, which I think we do have to make some of the javascript easier to read, such as finding chained parent nodes.

mok4ry commented 8 years ago

jQuery is a dependency of Bootstrap, but that doesn't mean it should be a dependency of ours. What if we remove Bootstrap in the future? We'll be left tied to jQuery as a dependency.

I find jQuery to be hardly necessary as the ECMAScript spec evolves. We get things like document.querySelector for free nowadays.

I'd go so far as to claim that if you find yourself "needing" jQuery, it's time to take a step back and reevaluate your approach. See if you can't simplify the markup structure or introduce better id/class/ general attribute practices to eliminate things like chained parent node references. Using jQuery to make such a practice "look better" in code is like covering a burnt cake with pretty icing: it still ends up tasting bad.

varzaman commented 8 years ago

Here are the options to get certain elements:

Either you get the parent or child node(and chain them), or you have to get an element by ID, tag name, or class. Since that is what we have to work with, all solutions need to take that into account. The elements are dynamically created by clone, so they have no identifiers.

So options: Get the elements by chaining parent Nodes(how it is currently done) Dynamic IDs to be used as reference Make our own function

The function could be something like getNodeUpChain(int n), where n is how far up the chain.

lukecoy commented 8 years ago

I agree with @mok4ry full heartedly. I don't think there's really any use case I can think of where jQuery will best vanilla javascript for the scope of our project. Like he said, we have to be careful about pumping JS libraries into our code to bandage up HTML.

I think it's safe to say that there's a push in the development community to prefer Vanilla over JQuery - and even if our dependencies rely on it in the present, I can't imagine that the developers of those dependencies are going to be content with a relic of web development in the close future. Introducing JQuery because a libraries source needs it anyway isn't a good enough rationale in my opinion.

I promise that whatever use cases we are running into where we need JQuery can be conquered by 1. Rightful refactoring or 2. Searching around MDN, W3 for a minute.

varzaman commented 8 years ago

I would say there is a push in the community, but a simple search would show you how there is no consensus about it. Pretty much arguments galore haha.

But regardless, I will now agree that having jQuery for one issue isn't worth it, especially when we have solutions to fix the readability.

Personally I say writing a function is the simplest way to make it readable. Simple for loop from 0 - n where n is the number of steps you want to go up. Then you just call that function instead of having .parentNode.parentNode.parentNode.parentNode. Readable and reusable.

mok4ry commented 8 years ago

It seems we're leaning toward removing Bootstrap in favor of Pure CSS, which means we won't have jQuery as a dependency for anything.

So, no jQuery.