Skip to content

Instantly share code, notes, and snippets.

@vinhlh
Created November 18, 2016 10:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinhlh/1268d389f0d55edce463eece1bc3b532 to your computer and use it in GitHub Desktop.
Save vinhlh/1268d389f0d55edce463eece1bc3b532 to your computer and use it in GitHub Desktop.
Typehead facebook search implement
m.prototype.throttleSendRemoteQuery = function() {
'use strict';
var n = c('FacebarGlobalOptions').sendRemoteQueryThrottleTime;
if (n === 0) {
this.sendRemoteQueryThrottled = this.sendRemoteQuery;
} else if (c('FacebarGlobalOptions').lazyThrottleRemoteQuery) {
var o = Date.now()
, p = c('FacebarGlobalOptions').enableSendRemoteQueryDelay
, q = c('FacebarGlobalOptions').sendRemoteQueryDelayTime;
this.sendRemoteQueryThrottled = function() {
for (var r = arguments.length, s = Array(r), t = 0; t < r; t++)
s[t] = arguments[t];
var u = Date.now();
if (o + n < u) {
o = u;
if (p) {
c('setTimeoutAcrossTransitions')(function() {
this.sendRemoteQuery.apply(this, s);
}
.bind(this), q);
} else
this.sendRemoteQuery.apply(this, s);
}
}
.bind(this);
} else {
if (c('FacebarGlobalOptions').typingSpeedThrottleTime > 0)
n = c('FacebarGlobalOptions').typingSpeedThrottleTime;
this.sendRemoteQueryThrottled = c('throttle').withBlocking(this.sendRemoteQuery, n, this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment