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
Different match and unmatch orders #38
Comments
Hey @mjlescano! I understand the issue, and don't worry your english was fine :) This issue was previously raised in issue #29, it is because of the way enquire currently does things - it simply loops through all registered queries, tests their state and acts accordingly. However, in future enquire will depend on the browser's native API for this kind of thing, and with that the same problem raises it's head - it seems even the browser itself does not guarantee order of callbacks. You can see a thorough breakdown in this comment: #29 (comment) I have converted your example to use 100% native methods as described in the comment above. You will notice that the order is not consistent.: I realised there was a potential flaw with my previous reasoning however, because I'm not sure whether this is intended or not, is it a browser bug or following the spec? Perhaps needs more investigation. Hope this helps either way |
Nick! ;(function(){
var to_unmatch = null
enquire.register2 = function(q, options, shouldDegrade){
if( typeof options === 'function' ) {
options = {match: options}
}
var match = options.match, unmatch = options.unmatch
if( unmatch ) delete options.unmatch
options.match = function(){
if( to_unmatch ){
to_unmatch()
to_unmatch = null
}
if( unmatch ){
to_unmatch = unmatch
}
match()
}
return enquire.register(q, options, shouldDegrade)
}
})() |
Sorry @mjlescano thought I had replied to you here! Glad you worked out a solution in the end :) I'll close this issue for now, but if you want to discuss anything further, please feel free! |
@mjlescano Thanks for posting you solution to this problem. It worked like a dream, full of win! |
How are we supposed to use the piece of code that @mjlescano posted? Sorry, I'm not that good in JS. UPDATE: |
This is not a browser bug. It follows the specifications. Javascript event queue is a simple FIFO, first registered — first fired. If you register event A and then register event B, it will guarantied that A will always run before B on a compliant browser. |
Match and unmatch functions are triggered in different order when going smaller than going big.
I made this fiddle to compensate my rusty english
http://jsfiddle.net/mjlescano/FmmTa/3/embedded/result/
Tested resizing the window,
reducing the window width the triggers are:
match:bigger
unmatch:bigger
match:normal
making bigger the window, triggers:
match:normal
match:bigger
unmatch:normal
It should be
match:normal
unmatch:normal
match:bigger
The text was updated successfully, but these errors were encountered: