-
Notifications
You must be signed in to change notification settings - Fork 793
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use lodash's debounce for maxWait functionality
- Loading branch information
Showing
1 changed file
with
4 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import embed from "https://cdn.jsdelivr.net/npm/vega-embed@6/+esm"; | ||
import debounce from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm' | ||
import { debounce } from "https://cdn.jsdelivr.net/npm/[email protected]/lodash.js" | ||
|
||
export async function render({ model, el }) { | ||
let finalize; | ||
|
@@ -32,6 +32,7 @@ export async function render({ model, el }) { | |
|
||
// Debounce config | ||
const wait = model.get("debounce_wait") ?? 10; | ||
const maxWait = wait; | ||
|
||
const initialSelections = {}; | ||
for (const selectionName of Object.keys(model.get("_vl_selections"))) { | ||
|
@@ -43,7 +44,7 @@ export async function render({ model, el }) { | |
model.set("_vl_selections", newSelections); | ||
model.save_changes(); | ||
}; | ||
api.view.addSignalListener(selectionName, debounce(selectionHandler, wait, true)); | ||
api.view.addSignalListener(selectionName, debounce(selectionHandler, wait, {maxWait})); | ||
|
||
initialSelections[selectionName] = {value: {}, store: []} | ||
} | ||
|
@@ -57,7 +58,7 @@ export async function render({ model, el }) { | |
model.set("_params", newParams); | ||
model.save_changes(); | ||
}; | ||
api.view.addSignalListener(paramName, debounce(paramHandler, wait, true)); | ||
api.view.addSignalListener(paramName, debounce(paramHandler, wait, {maxWait})); | ||
|
||
initialParams[paramName] = api.view.signal(paramName) ?? null | ||
} | ||
|