cache path name to avoid race conditions when updating url
This commit is contained in:
parent
d219bde48d
commit
6bbd35d644
2 changed files with 6 additions and 5 deletions
|
@ -237,10 +237,10 @@ const Util = {
|
||||||
return obj
|
return obj
|
||||||
}, {})
|
}, {})
|
||||||
},
|
},
|
||||||
updateQueryParams: function(newValues) {
|
updateQueryParams: function(newValues, pathname = window.location.pathname) {
|
||||||
const qp = Object.assign({}, Util.queryParams(), newValues)
|
const qp = Object.assign({}, Util.queryParams(), newValues)
|
||||||
const newString = Object.keys(qp).filter(key => !!key).map(key => `${key}=${qp[key]}`).join('&')
|
const newString = Object.keys(qp).filter(key => !!key).map(key => `${key}=${qp[key]}`).join('&')
|
||||||
history.replaceState({}, document.title, `${window.location.pathname}?${newString}`)
|
history.replaceState({}, document.title, `${pathname}?${newString}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* global $ */
|
/* global $, window */
|
||||||
|
|
||||||
import { find as _find, indexOf as _indexOf, uniq as _uniq, debounce } from 'lodash'
|
import { find as _find, indexOf as _indexOf, uniq as _uniq, debounce } from 'lodash'
|
||||||
|
|
||||||
|
@ -151,8 +151,9 @@ const Visualize = {
|
||||||
|
|
||||||
// monkey patch scale function
|
// monkey patch scale function
|
||||||
const oldScale = self.mGraph.canvas.scale
|
const oldScale = self.mGraph.canvas.scale
|
||||||
|
const cachedPathname = window.location.pathname
|
||||||
const updateScaleInUrl = debounce(() => {
|
const updateScaleInUrl = debounce(() => {
|
||||||
Util.updateQueryParams({ scale: self.mGraph.canvas.scaleOffsetX.toFixed(2) })
|
Util.updateQueryParams({ scale: self.mGraph.canvas.scaleOffsetX.toFixed(2) }, pathname)
|
||||||
}, 200)
|
}, 200)
|
||||||
self.mGraph.canvas.scale = function(x, y, disablePlot) {
|
self.mGraph.canvas.scale = function(x, y, disablePlot) {
|
||||||
const returnValue = oldScale.apply(self.mGraph.canvas, arguments)
|
const returnValue = oldScale.apply(self.mGraph.canvas, arguments)
|
||||||
|
@ -165,7 +166,7 @@ const Visualize = {
|
||||||
const updateTranslateInUrl = debounce(() => {
|
const updateTranslateInUrl = debounce(() => {
|
||||||
const newX = self.mGraph.canvas.translateOffsetX.toFixed(2)
|
const newX = self.mGraph.canvas.translateOffsetX.toFixed(2)
|
||||||
const newY = self.mGraph.canvas.translateOffsetY.toFixed(2)
|
const newY = self.mGraph.canvas.translateOffsetY.toFixed(2)
|
||||||
Util.updateQueryParams({ translate: `${newX},${newY}` })
|
Util.updateQueryParams({ translate: `${newX},${newY}` }, pathname)
|
||||||
}, 200)
|
}, 200)
|
||||||
self.mGraph.canvas.translate = function(x, y, disablePlot) {
|
self.mGraph.canvas.translate = function(x, y, disablePlot) {
|
||||||
const returnValue = oldTranslate.apply(self.mGraph.canvas, arguments)
|
const returnValue = oldTranslate.apply(self.mGraph.canvas, arguments)
|
||||||
|
|
Loading…
Add table
Reference in a new issue