Airblader commented on a change in pull request #18581: URL: https://github.com/apache/flink/pull/18581#discussion_r796524828
########## File path: docs/static/js/track-search-terms.js ########## @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +/* Based on https://stackoverflow.com/questions/24004791/can-someone-explain-the-debounce-function-in-javascript */ +function debounce(func, wait, immediate) { + // 'private' variable for instance + // The returned function will be able to reference this due to closure. + // Each call to the returned function will share this common timer. + var timeout; + + // Calling debounce returns a new anonymous function + return function() { + // reference the context and args for the setTimeout function + var context = this, + args = arguments; + + // Should the function be called now? If immediate is true + // and not already in a timeout then the answer is: Yes + var callNow = immediate && !timeout; + + // This is the basic debounce behaviour where you can call this + // function several times, but it will only execute once + // [before or after imposing a delay]. + // Each time the returned function is called, the timer starts over. + clearTimeout(timeout); + + // Set the new timeout + timeout = setTimeout(function() { + + // Inside the timeout function, clear the timeout variable + // which will let the next execution run when in 'immediate' mode + timeout = null; + + // Check if the function already ran with the immediate flag + if (!immediate) { + // Call the original function with apply + // apply lets you define the 'this' object as well as the arguments + // (both captured before setTimeout) + func.apply(context, args); + } + }, wait); + + // Immediate mode and no wait timer? Execute the function.. + if (callNow) func.apply(context, args); + } +} + +// Function which is called to track the actual search term +function trackSearchQuery(e){ + const searchHits = window.bookSearchIndex.search(input.value, 10); Review comment: I'm not sure what exactly this does, but do we just run the search query twice, once for the tracking? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
