Skip to content
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

Frontend: GitHub repo info controller: debounce API requests within a one-second time window #12773

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
* limitations under the License.
*/
import { Controller } from "@hotwired/stimulus";
import { debounce } from "debounce";

const debouncedFetch = debounce(fetch, 1000);

export default class extends Controller {
static targets = [
Expand All @@ -25,12 +28,18 @@ export default class extends Controller {
static values = { url: String };

// TODO: Why does this fire twice? Is it because of the position of CSI?
// Answer:
// The repo info controller appears twice on the package detail page; once
// within 'sidebar' navigation elements, and once within 'vertical tab'
// navigation elements. Each controller instance's 'connect' function is
// invoked once.
connect() {
this.load();
}

load() {
fetch(this.urlValue, {
// TODO: Seems to work, but also raises a TypeError (value is undefined)?
debouncedFetch(this.urlValue, {
method: "GET",
mode: "cors",
})
Expand Down