Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Use new @plotly/dash-component-plugins to handle location path changes #743

Merged
merged 7 commits into from
Jan 29, 2020

Conversation

Marc-Andre-Rivet
Copy link
Contributor

@Marc-Andre-Rivet Marc-Andre-Rivet commented Jan 27, 2020

Linked to plotly/dash#1094

  • changelog entry
  • new dcc.Link / dcc.Location test on link click, browser forward, browser backward

…ponents

- use component plugins to emit global event from location component
package.json Outdated Show resolved Hide resolved
@@ -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'));
Copy link
Contributor Author

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
);
Copy link
Contributor Author

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"

Copy link
Contributor

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

@Marc-Andre-Rivet Marc-Andre-Rivet marked this pull request as ready for review January 27, 2020 16:27
Copy link
Contributor

@wbrgss wbrgss left a 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
);
Copy link
Contributor

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
Copy link
Contributor Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants