Skip to content

Commit

Permalink
Use lodash's debounce for maxWait functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmmease committed Aug 1, 2023
1 parent 2e4a48e commit 0fa4723
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions altair/jupyter/js/index.js
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;
Expand Down Expand Up @@ -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"))) {
Expand All @@ -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: []}
}
Expand All @@ -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
}
Expand Down

0 comments on commit 0fa4723

Please sign in to comment.