Skip to content

Commit

Permalink
Debounce state change
Browse files Browse the repository at this point in the history
  • Loading branch information
unidesigner committed Dec 1, 2023
1 parent 77ef8ba commit d48643b
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/neuroglancer/ui/default_viewer_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import debounce from "lodash/debounce";
import { StatusMessage } from "neuroglancer/status";
import {
bindDefaultCopyHandler,
Expand All @@ -34,12 +35,16 @@ export function setupDefaultViewer() {
setDefaultInputEventBindings(viewer.inputEventBindings);

const hashBinding = viewer.registerDisposer(
new UrlHashBinding(viewer.state, viewer.dataSourceProvider.credentialsManager, {
defaultFragment:
typeof NEUROGLANCER_DEFAULT_STATE_FRAGMENT !== "undefined"
? NEUROGLANCER_DEFAULT_STATE_FRAGMENT
: undefined,
})
new UrlHashBinding(
viewer.state,
viewer.dataSourceProvider.credentialsManager,
{
defaultFragment:
typeof NEUROGLANCER_DEFAULT_STATE_FRAGMENT !== "undefined"
? NEUROGLANCER_DEFAULT_STATE_FRAGMENT
: undefined,
}
)
);
viewer.registerDisposer(
hashBinding.parseError.changed.add(() => {
Expand All @@ -59,11 +64,16 @@ export function setupDefaultViewer() {
bindDefaultPasteHandler(viewer);

if (viewer.state) {
viewer.state.changed.add(() => {
if (window && window.parent) {
window.parent.postMessage({ type: "state_change", state: viewer.state.toJSON() }, "*");
}
});
viewer.state.changed.add(
debounce(() => {
if (window && window.parent) {
window.parent.postMessage(
{ type: "state_change", state: viewer.state.toJSON() },
"*"
);
}
}, 400)
);
}

return viewer;
Expand Down

1 comment on commit d48643b

@vercel
Copy link

@vercel vercel bot commented on d48643b Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.