cache path name to avoid race conditions when updating url

This commit is contained in:
Devin Howard 2016-12-18 17:11:49 -05:00
parent d219bde48d
commit 6bbd35d644
2 changed files with 6 additions and 5 deletions

View file

@ -237,10 +237,10 @@ const Util = {
return obj
}, {})
},
updateQueryParams: function(newValues) {
updateQueryParams: function(newValues, pathname = window.location.pathname) {
const qp = Object.assign({}, Util.queryParams(), newValues)
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}`)
}
}

View file

@ -1,4 +1,4 @@
/* global $ */
/* global $, window */
import { find as _find, indexOf as _indexOf, uniq as _uniq, debounce } from 'lodash'
@ -151,8 +151,9 @@ const Visualize = {
// monkey patch scale function
const oldScale = self.mGraph.canvas.scale
const cachedPathname = window.location.pathname
const updateScaleInUrl = debounce(() => {
Util.updateQueryParams({ scale: self.mGraph.canvas.scaleOffsetX.toFixed(2) })
Util.updateQueryParams({ scale: self.mGraph.canvas.scaleOffsetX.toFixed(2) }, pathname)
}, 200)
self.mGraph.canvas.scale = function(x, y, disablePlot) {
const returnValue = oldScale.apply(self.mGraph.canvas, arguments)
@ -165,7 +166,7 @@ const Visualize = {
const updateTranslateInUrl = debounce(() => {
const newX = self.mGraph.canvas.translateOffsetX.toFixed(2)
const newY = self.mGraph.canvas.translateOffsetY.toFixed(2)
Util.updateQueryParams({ translate: `${newX},${newY}` })
Util.updateQueryParams({ translate: `${newX},${newY}` }, pathname)
}, 200)
self.mGraph.canvas.translate = function(x, y, disablePlot) {
const returnValue = oldTranslate.apply(self.mGraph.canvas, arguments)