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

Removing jQuery (upcoming PR) #8

Closed
nicinabox opened this issue Jun 10, 2014 · 7 comments
Closed

Removing jQuery (upcoming PR) #8

nicinabox opened this issue Jun 10, 2014 · 7 comments

Comments

@nicinabox
Copy link
Contributor

Re #5, I have refactored to remove the jQuery dependency, but I'm not sure how to really go about testing it. It would be great if you could review my branch. I'd be happy to send a PR if you're good with it.

@athaeryn
Copy link
Contributor

Hey! Love that you did this. That said, I do already have a plan for how to remove the jQuery dependency.

It will be similar to Backbone.$. By default, Boba will try and use window.$. If it can't find that, you'll have to provide a shim object with functions compatible with jQuery's API, like this:

Boba.$ = {
  extend: function(target, object) { ... },
  on: function(element, event, selector, handler) { ... },
  proxy: function(func, context) { ... }
}

If you're using Underscore.js, you could use something like this:

Boba.$ = {
  extend: _.extend,
  proxy: _.bind,
  // Underscore doesn't have anything for this, we'd have to write it ourselves
  on: function(element, event, selector, handler) { ... }
}

The on function will be different, since it's called on a jQuery object. I'm thinking Boba will include something like this:

Boba.$.on = function(el) {
  Boba.$.fn.on.apply($(el), Array.prototype.splice.call(arguments, 1))
}

The point is, I don't want Boba to include ancillary functions. I'd rather have a shims/ folder, and probably have different builds using each of the shims.

I'd love to hear other people's thoughts!

@nicinabox
Copy link
Contributor Author

My first thought as a developer is, "Yeah, shims would be cool!", but my first thought as a user is, "Why can't it just work OOTB?"

The level of complexity necessary to hide a loop and a closure is crazy. And you still don't get a good listener for on.

Boba tries to make working with GA easier, right? IMO, supplanting the user's problem (tracking) with writing extra methods just to get it to work seems dubious.

@athaeryn
Copy link
Contributor

Oh, it would work out of the box with jQuery, and there would be other versions (in a dist/ folder or something) that would work with things like Underscore.js or just vanilla JS.

@athaeryn
Copy link
Contributor

Sorry, I probably didn't explain very well before. Boba at it's core would use jQuery if present, and require a shim otherwise. The shims would live in a shims/ folder, so that anyone could contribute one. I'd add a gulp task to build each shim into the dist/ folder, so you could grab, say, a jQuery-free version from there.

@nicinabox
Copy link
Contributor Author

It's up to you ultimately how you want to do it. I think it's a bit silly to shim a for loop and a closure. There's nothing wrong with these patterns or having them in the core code. The complexity created by offloading to dependency x creates far more friction for maintenance/contributors and end users.

Suddenly it becomes not an easy drop in replacement-- you need to know something about it, you need to pick the right shim and be aware of potential conflicts. For a 100-line abstraction, that kind of peripheral knowledge shouldn't be a prerequisite.

@bradgreens
Copy link

An idea could be to stick mainly to ES5 methods, such as Array.prototype.forEach and suggest the ES5-shim for users needing to support IE8 or other non-compliant browsers. I think writing it lean and adding an ES5 or jQuery adapter is a good pattern. It would support those who require wide-range browser support, and those of us who do not have that concern.

@athaeryn
Copy link
Contributor

athaeryn commented Jul 4, 2014

I think I'm just going to merge this (when you submit the PR). Eventually I'll get around to implementing things the way I'd like them, but this is good for now.

@athaeryn athaeryn closed this as completed Jul 4, 2014
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

No branches or pull requests

3 participants