Looks good. Except when you type a single space character the app enters into an infinite loop making it very difficult to do anything else in the browser (Chrome). Even navigating the window to a different page is impossible.
[Edit] Scratch that. Typing anything followed by a space character tends to make things crash. Why would this happen? I find this bug interesting. Let me know what the problem was when you fix it.
[Edit2] Okay looks like the problem may be with anything that needs to be url encoded.
[Edit3] I think the problem comes down to your call to encodeURIComponent in your search function and the behavior when the hash changes. Basically, we enter the search function when the hash changes. But then you call encodeURIComponent and assign the result to the hash. If the query contains characters that need to be escaped then the new value is different (meaning the hash changes), which means that your search function is going to get called ad infinitum.
In order to fix this I think you need to do two things. 1) Keep track of the in flight request unencoded and 2) if your search function is triggered by a hash change decode the query and compare it to your in flight request. If they are the same then you can bail out of the search function early. Otherwise you should cancel the in flight request and launch a new one.
how come this post is still on top with such a serious bug?
Hitting space makes it enter into infinite loop.
It crashed my browser while I was in middle of something important.
[Edit] Scratch that. Typing anything followed by a space character tends to make things crash. Why would this happen? I find this bug interesting. Let me know what the problem was when you fix it.
[Edit2] Okay looks like the problem may be with anything that needs to be url encoded.
[Edit3] I think the problem comes down to your call to encodeURIComponent in your search function and the behavior when the hash changes. Basically, we enter the search function when the hash changes. But then you call encodeURIComponent and assign the result to the hash. If the query contains characters that need to be escaped then the new value is different (meaning the hash changes), which means that your search function is going to get called ad infinitum.
In order to fix this I think you need to do two things. 1) Keep track of the in flight request unencoded and 2) if your search function is triggered by a hash change decode the query and compare it to your in flight request. If they are the same then you can bail out of the search function early. Otherwise you should cancel the in flight request and launch a new one.