-
Notifications
You must be signed in to change notification settings - Fork 176
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
Reduce / remove jQuery dependency to support Backbone#3003 #211
Comments
Love the effort. Currently using exoskeleton (backbone fork without jquery) in a new project and I went with rivets model bindings rather than stickit this time just to get the taste of something different. Would love to see jquery free stickit. |
Glad you like. Exoskeleton is the other side of the jQuery-free coin. Any ideas on what's needed to get the rest of the jQuery bindings out of Stickit? Maybe we should push as stickit version 2? |
I like the way you do it in chaplin @akre54 but perhaps it will generate to many "if jquery do this, else do this" in stickit. shims are no no. i dont like them. and i think the browsermarket, seeing the latest versions at least, have a pretty nice baseline of modern support. if one needs older support, just use jquery - which is still a great framework. I dont think there is a lot of dom manipulation i do frequently with backbone, thats one of the reasons i challanged my self to not use jquery in a new project. It turned out its mostly classList stuff, finding elements and get values/attributes or set innerHTML |
In general I'm not a fan of the logic branching you describe, mostly because its ugly and can be better handled in View, or with native methods in the simple case. I think Chaplin goes a little overboard in that regard, and if it's possible to keep it simple and only within View, I'd like to figure out how to make that work. |
What's up @akre54, @andriijas - @akre54 - I'm trying to catch up on your backbone pull and look through stickit to see what it would take to go native. I'm not concerned about shimming or working with native attributes and classes. The lack of find could prove difficult, especially for the pseudo-selectors. What do the shims for that look like? I would also like to know what the shim for namespace support looks like. As an alternative to namespacing/shimming, we could manage our own bookkeeping of view events, similar to the Overall, the backbone pull looks nice. It's minimal, as it should be in backbone, and I think we can deal with the issues it brings to stickit. @andriijas - sup on rivets? ...have any feedback? |
There are no pseudo-selectors, just selectors that can be found with qsa. Find (a.k.a. The new goal with 3003 is to avoid namespaces altogether and instead keep track of the references ourselves, just like we do in Stickit with model bindings. I'm a little busy the next few days, but I'm hoping to get a few minutes to whip up a compatible Stickit that has most of the major concepts in place. Let me know if there's anything that immediately stands out to you. |
I think its good to try to not use psuedo selectors anyway, and if you do, there is jquery :) Regarding rivets, well I started a new backbone project with as few dependencies as possible to widen my knowledge about javascript but in the end there was a couple of forms that just made everything simple and elegant with bindings so I opted to try rivets. Ive been anti with putting the logic in the html before so I wanted to challange my self. I think its nice for the simple things ive been doing this far. Im sure its possible to extend for more advanced stuff too but the way stickit works with handlers is straight forward (for me at least) and allows for easy flexibility, if you need small alterations its easy because your binding is already in your view logic. with rivets, if you need small difference from what you put in your html, you need logic elsewhere AND in html. That said Ive been enjoying stickit for 1 year and 3 months. Ive only been using rivets for 2 months :) |
I opened a pull at jashkenas/backbone#3003 which attempts to remove the hard jQuery dependency from within Backbone.View, and it seems Stickit would be a good place to start answering some of the tougher issues of integrating features of that pull in View plugins.
3003 removes the guarantee of a
view.$el
property, instead suggesting that plugins useview.el
. It introduces an exposeddelegate
method on View that allows View to do some bookkeeping for delegated events (so we can avoidthis.$el.on
calls) and later remove those events withundelegateEvents
. Lastly, it changes the contract onview.$
(i.e.view.$('.selector')
) element lookup method to return an array-like object that has Elements in each of the numbered slots.view.$
may return an array, a NodeList or a jQuery object and they should all work correctly. This means that we have to iterate over the return value fromview.$
with_.each
.For the most part, implementing a DOM library-agnostic set of features in Stickit shouldn't be too tough. We already use
_.each
to iterate over many of the element collections returned fromview.$
and event delegation could be changed fromthis.$el.on(...)
tothis.delegate(...)
, but there are a number of places we use$el.find
with pseudo-selectors andaddClass
/removeClass
that could make using native methods difficult without adding shims for old libraries (i.e. requiringquerySelectorAll
andclassList
shims might be necessary.)Then there is the question of adding an
undelegate
method to View to allow undelegating specific namespaces or selectors without blowing away all events from the View or relying onthis.$el.off
. Stickit uses namespaces to handle bookkeeping and removal at the end, and it relies on the jQuery-specific feature of passing a selector or map of selectors tooff
, which could be difficult to force all implementations to add. One of the main goals of 3003 is to determine what features all View subclasses should support as a baseline, and some insight there could prove useful.@delambo, mind chiming in here or in 3003 to offer some insight into what you think it would take to get Backbone and Stickit jQuery-free?
The text was updated successfully, but these errors were encountered: