Native view and jQuery-less History#2959
Conversation
…y-enabled View a small subclass of BaseView.
There was a problem hiding this comment.
Seems like if we're going to have a standards-based BaseView and a regular jQuery View that BaseView should be as slim as possible and only care about the latest browsers / modern web standards, rather than selectively implementing polyfills for some browsers (IE8) but not others (IE7) - leave jQuery for people who care about old browsers.
There was a problem hiding this comment.
Normally I'd agree but that's just 15 lines of extra code. I'd pay an extra 300 bytes for compatibility. That and many of my clients using Backgrid are still on their network's IE8. The jQuery based View is already slow on most modern browsers. It's unbearable on IE8.
|
Ok npm test weirdness with PhantomJS and CommonJS fixed. |
|
I think the remaining 2 issues are, do we want compatibility with IE8 in BaseView? And are the BaseView/View naming and arrangement OK? |
|
@wyuenho What exactly is the question about polyfills? |
|
@philfreo said the addEventListener/removeEventListener/matchesSelector shims shouldn't be in Backbone because people who care could just use the jQuery backed View. @paulmillr Wants the private matchesSelector polyfill exposed and reachable. I just want to know whether you think it's worthwhile to keep the polyfills first, if not, lots of problems become moot. |
That's probably true.
I don't think so. We should keep the internal workings private and hidden. |
|
Yep. I don't think it's Backbone's jobs to provide polyfills either. Should I remove the polyfills and compat code for IE8 in BaseView then? |
|
If you're going to use jQuery for backwards compatibility, then yes. |
|
Ok IE8 compat code gone. |
|
Are you fine with the BaseView and View arrangement? |
|
Ahhh actually @jashkenas I think I'm gonna put the IE8 compat code back because I just realized the router is using jQuery too. It's totally unnecessary and removing that dependency while preserving compatibility will have to use the addEventListener/removeEventListener shims. The compat code really isn't that big. |
This reverts commit 64dce64.
…m being including in IE<=7
…IE and Safari, and remove jQuery dependency in Router
|
Ok the Router is now rid of jQuery dependency. Tests still pass on all modern browsers and IE8+ |
There was a problem hiding this comment.
Would it be possible to not necessitate this if check upon every invocation? Small optimization but should be a simple one.
There was a problem hiding this comment.
Well if you want to go after absolute speed then yes I can optimize not only the if statement but the entire extra function call away.
But since IE and Safari's window.addEventListener != Element.prototype.addEventListener, I'll have to litter 4 more if statements inside the Router to preserve IE8 compatibility.
If we decide to drop IE8 support (which I think is reasonable), then I can remove the event listener shims altogether. In fact, we could probably drop the jQuery-backed View as well if that's the case. Still waiting for the word on this one from other Backbone core devs.
cc. @braddunbar @caseywebdev @philfreo @tbranyen @tgriesser @akre54 @wookiehangover @gsamokovarov @jashkenas
Do you have a better idea that doesn't regress back to something like #2865? |
Have Backbone expose API that can be hooked into by adapters instead of funneling everything through It's similar to what you're doing in BaseView except would be separate of Backbone.js. |
|
Which is basically #2865's The major contention remaining seems to be IE8 support in
All options are either asking too much or halfway there but not enough. After writing |
I figured you would say that, which is why I snipped your quote in my reply :)
Sure it can. If there's something preventing it, expose an API point.
Talking about performance before there's an implementation is a bit premature.
I think you're missing my greater point. I've shown, using CanJS as an example, that adapters can be made to address a variety of issues and don't necessarily belong in core. Nothing is preventing your This would keep Backbone minimal, without having to get into the DOM realm, and still allow for 3rd-party adapters to address a variety of needs. |
|
@Dw40 Talk is cheap. Talking about theoretical possibilities without concrete implementations is even cheaper. Show me some code that doesn't look like #2865 or Backbone.Native or Backgrid.View, which is basically a rewrite of View, that is equally fast as BaseView. |
I've pointed to another real MV* framework using adapters successfully. There's your concrete real world implementation 😀. The specifics of how one does it is less interesting, the important thing is ensuring Backbone doesn't throw up roadblocks preventing it from being done.
It's not my or Backbone's responsibility to create another DOM adapter. Backbone should just make sure it isn't blocking that from happening. Developers have different browser compat needs and I don't think its Backbone's concern to address. @braddunbar @akre54 I think this PR should be closed and, if anything, the effort refocused on ensuring Backbone isn't blocking native barebone adapters from being made. |
|
If you can't back up your claim that having an extra adaptor can satisfy the requirements as well as this PR, or contribute to a discussion constructively by offering feasible suggestions, please hold your peace. Backbone doesn't need another adapter, Backbone already has |
I've been offering feasible suggestions and constructive feeback, despite your attitude, but you've chosen to ignore it.
You've mentioned this a couple of times. I'm all for making it easier to swap out jQuery but again I don't think it requires Backbone taking on
Backbone.Native handles ajax, event namespaces, and a few other things not addressed by your |
|
@Dw40 How about you answer this question directly? as your main objection is (was?) IE8 support in
All this trollish behavior makes me very suspicious of your motives, especially when coming from someone who has a suspiciously recently opened Github account, who have 0 contribution to open source and someone who is obviously not a newcomer to Web development. Why are you so hell bent on derailing this PR? You obviously have no use for this PR, but is there anything specific that actually majorly affects you negatively? You may not need this, other people do. Now take your complain about every other feature you don't need in every other library that you've used somewhere else.
Well, show me code you would use to isolate jQuery from the View in your own application code without rewriting There will be no more reply from me to this thread. I've laid out every technical decision I've considered and presented the case why this PR is the best I can come up with to solve the problem of further isolating jQuery dependency and introducing a really fast If @jashkenas chooses an option from this list, I'll go make my amendments, otherwise take it or leave it. |
I have answered it.
Yes, among other things. I don't think Backbone needs to get into the DOM, or its compat, any more than it has to. You brought up Backbone.Native, which looks a lot like
You've thrown a lot of stones there.
I think you're mixing up trollish behavior with those like @braddunbar, @tbranyen, and myself who respectfully disagree with the PR and think it isn't needed in core. I've been replying to make that case.
I disagree when there are options like |
|
Jimmy, please stop arguing with this dude. I don't think his opinion is relevant. What matters to us, is Jeremy's, or maybe other maintainers thoughts. |
|
nah, the problems with jQuery-compliant API "adapters" are twofold:
It's much more efficient and logical for Backbone to expose its DOM manipulation API as a set of pluggable options that can be overridden on the fly (a la earlier versions of #2865). I not a fan of the separate View/BaseView classes, and I think #2865 should have been more than sufficient (minus |
|
@akre54 How do you suppose we could preserve backward compatibility with |
|
$el is only if you have a jquery analog. Otherwise theres just el. My only question is about view.$
|
|
So now all of a sudden the existence of |
|
But they cant rely on $el from base view to have a jquery-compatible interface anyway. Best just to rely on el, which all views will have, or check for |
|
There's no I don't understand why |
|
Because in my mind, either you're going jquery or you're going native. Any other adapter you're using a Backbone.$ analogue anyway. If you want them both on the same page, that screams plugin to me. |
|
All plugins have to start somewhere. It's not possible to extend View to use another DOM lib or the DOM API without a complete rewrite of View. This PR provides a You may start out native only or jQuery only, but eventually you'll have to mix in both if you want to speed things up or have greater compatibility. You don't see that now only because it's not possible now. This PR surpasses #2865, which was closed by the way, in terms of flexibility due to its granularity, while introducing a lot less code. What's not to like about that? This PR supersedes #2865. This continuing theme of binary all-or-nothing mode of thought is very perplexing. |
|
Just curious, @akre54, would this PR taste better if I introduced |
Yeah that sounds reasonable. If our focus is on removing jQuery from View specifically, why not have hooks in View for things like |
This PR improves on PR #2865:
addEventListenerandremoveEventListenerfor IE8.matchesSelectorimplementationremovewhere PR#2865 confuses removal with detachment.$.fn.removewill remove event handlers while PR#2865 does not. Failure to do so will make some event handlers depending on this behavior fail. This broke Backgrid.setElementthat's more faithful to jQuery's behavior. The code is improved from Backbone.native. Specifically, you can supply an HTML snippet, a CSS selector or a DOM element, just like jQuery.useNativeflag and branching. The oldViewhad been extracted intoBaseViewand_ensureElement,setElement,delegateEventsandundelegateEventsuses native APIs. So Backbone will have a baseline View that's fast by default.BaseView#$just delegates tothis.el.querySelectorAlland returns a node list.View#findandView#findAll. They add no value and it's not even the correct implementation of the proposed Selectors API Level 2 spec._delegateEventsand_undelegateEventsfor subclasses to override.BaseView#_delegateEventandBaseView#_undelegateEventsin place ofutil.delegateandutil.undelegate.BaseView#_delegateEventwill also work on IE8.utils. This PR has effectively removes hard dependency on jQuery already by pulling out a BaseView that's basically the old view + 2 hooks and all native DOM API calls. The only remaining dep on$.ajaxcan be overcome easily by replacing Backbone.ajax with one of the many $.ajax alternative implementations out there.Backbone.Viewis a 26 line extremely light weight subclass ofBackbone.BaseViewthat's 100% backward compatible with the old jQuery-based View.Tests passed on:
Performance:
http://jsperf.com/backbone-patch-22be8f9/2
Around 70% faster than the jQuery-based View and slightly faster than #2865, by a couple of percentages consistently.
Remaining issues:
BaseViewbe called something else? Should the native View subclass a refactored jQuery-based View instead? Code size will be exactly the same.BaseView? See options here.cc. @paulmillr @akre54