Skip to content

Commit

Permalink
added ability to upgrade state in UrlHashBinding.updateFromUrlHash fo…
Browse files Browse the repository at this point in the history
…r backwards compatibilty
  • Loading branch information
chrisj committed Oct 22, 2024
1 parent 1266654 commit fe3ec56
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/ui/default_viewer_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,19 @@ export function setupDefaultViewer() {
hashBinding.parseError;
}),
);
hashBinding.updateFromUrlHash();
hashBinding.updateFromUrlHash((state) => {
// convert graphene state timestamp to layer timestamp
if (state.layers) {
state.layers.map((layer: any) => {
if (layer.source?.state?.timestamp) {
layer.timestamp = layer.source.state.timestamp;
layer.source.state.timestamp = undefined;
}
});
}

return state;
});
viewer.registerDisposer(bindTitle(viewer.title));

bindDefaultCopyHandler(viewer);
Expand Down
4 changes: 2 additions & 2 deletions src/ui/url_hash_binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class UrlHashBinding extends RefCounted {
* Sets the current state to match the URL hash. If it is desired to initialize the state based
* on the URL hash, then this should be called immediately after construction.
*/
updateFromUrlHash() {
updateFromUrlHash(upgradeState: (a: any) => any = (x) => x) {
try {
let s = location.href.replace(/^[^#]+/, "");
if (s === "" || s === "#" || s === "#!") {
Expand Down Expand Up @@ -160,7 +160,7 @@ export class UrlHashBinding extends RefCounted {
this.root.reset();
const state = urlSafeParse(s);
verifyObject(state);
this.root.restoreState(state);
this.root.restoreState(upgradeState(state));
} else {
throw new Error(
`URL hash is expected to be of the form "#!{...}" or "#!+{...}".`,
Expand Down

0 comments on commit fe3ec56

Please sign in to comment.