-
Notifications
You must be signed in to change notification settings - Fork 0
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
Follow up for Chaplin#780 #2
Conversation
@@ -30,7 +30,11 @@ insertView = (list, viewEl, position, length, itemSelector) -> | |||
|
|||
if insertInMiddle or itemSelector | |||
# Get the children which originate from item views. | |||
children = list.querySelectorAll(itemSelector) | |||
if itemSelector |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the Chaplin style is
children = if itemSelector
list.querySelectorAll(itemSelector)
else
list.children
Fixed the coding style but i'm starting to think it wasn't worth push this. I've seen @paulmillr suggestion to throw early just after, but after some investigations, i 'm afraid it might be a breaking change. This jsbin demonstrate visually the behavior on master of a CollectionView with an itemSelector with or without listSelector. I've double checked with the tests on master with exos setup and this test pass, so it's definitively something supported. The failure come from Maybe we can come up with something like, based on my previous attempt and code from Exos (quickly done, untested and ugly) matchesSelector: (node, selector) ->
matches = node.matches || node.webkitMatchesSelector || node.mozMatchesSelector || node.msMatchesSelector
if !matchesSelector
throw new Error('Element#matches is not supported');
matches.call(node, selector)
filterChildren = (nodeList, selector) ->
return nodeList unless selector
for node in nodeList when matchesSelector node, selector
if $ and $(node).is(selector)
node
else if matchesSelector.call(node, selector)
node |
Why not prepend the
|
It could have been a nice solution indeed... But it throws an error in every browsers. A quick googling seems to indicate there's only very contrived solutions to use querySelectorAll with a child selector. |
Ah crap. I remember that. (It's a specific reason why we didn't move off jQuery a few years back, for instance). Any reason not to use this shim from Backbone.NativeView? |
The matches on children vs listSelector isn't ideal, but I can't imagine it would break many if any things. I'd also be fine dropping IE8 support, since almost every other browser supports matches natively. |
I've mixed feeling about that. It will require a major version bump, no? I'd rather go with the same shim than Backbone.NativeView, minus the prefixed version (excepted If we go down this route, the remaining question is do we expose |
I'd imagine any changes we make here would require a major version bump.
I dunno.... Firefox just dropped the I'm fine exposing on |
Feel free to make that change and I'll merge |
Change done, might need small tweaks to fit the coding style
My first idea was to ask you to not merge as is, as i intend to fix the tests with the Exos setup. Sidenote. If this get merged, maybe it's a good idea to squash 1c63e3e with the last commit to keep the original PR clean. |
|
||
(node, selector) -> | ||
matches.call(node, selector) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation is strictly the same than NativeView's one, except i've just slighly tweaked it to match the construct of beget
, indexOf
etc. Let me know if you prefer to keep it like the original.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I'm not a fan of functions wrapping a call
just to preserve a signature. I think it's fine if in filterChildren we do utils.matchesSelector.call node, selector
instead
Should be OK now. Commited separately 969a9e3 so it can be easily reverted / squashed in the original PR. |
Not green yet. Still one test failing.