-
-
Notifications
You must be signed in to change notification settings - Fork 144
Use new @plotly/dash-component-plugins to handle location path changes #743
Conversation
…ponents - use component plugins to emit global event from location component
src/components/Link.react.js
Outdated
@@ -47,7 +47,7 @@ export default class Link extends Component { | |||
window.location.pathname = href; | |||
} else { | |||
window.history.pushState({}, '', href); | |||
window.dispatchEvent(new CustomEvent('onpushstate')); | |||
window.dispatchEvent(new CustomEvent('_dashprivate_onpushstate')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make the link <--> location event explicitly private. No one outside of DCC should listen to this.
window.addEventListener( | ||
'_dashprivate_onpushstate', | ||
this.onLocationChange | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Location triggers a location changed
event on both (1) click on dcc.Link with refresh=false (default)
, (2) user clicking back
and forward
buttons in the browser UI. Prior to this change it was only possible to listen for (1)
with "onpushstate"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
the location history feature is working well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💃
window.addEventListener( | ||
'_dashprivate_onpushstate', | ||
this.onLocationChange | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
the location history feature is working well
) | ||
|
||
assert link_counter == 1 | ||
assert history_counter == 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple test making sure the events are being triggered by the components
Linked to plotly/dash#1094