Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/map routing #3508

Merged
merged 12 commits into from
Jul 5, 2018
Merged

Feature/map routing #3508

merged 12 commits into from
Jul 5, 2018

Conversation

edbrett
Copy link
Contributor

@edbrett edbrett commented Jul 3, 2018

Overview

This is a big one. Both in file changes and architecture, so please review with an open mind and with caution!

So the new map we are going to need to manage a large amount of state specific to many components on the page. Additionally this map needs to be able to exist in the map page, dashboards, and potentially other forms and pages. So how do we make sure we can manage the map state robustly, in isolation, and not have to faff around with lots of url and location functions every time we use the map. Simple! We use the same encoding method we have been using for the widgets, but with some updates:

  • we create a ?map=state key in the url and bind it to the url by creating a single setMapSettings action to dispatch to redux-first-router.
  • we move the previous decode and encode url to helpers that get triggered by the querySerializer of the router
  • we check inside the querySerializer encoder to make sure what we are dealing with is an object and then encode it and send to the url
  • the location key on the store is now holding the state of each component under a suitable key which can easily be passed to the component with its mapStateToProps and selectors.

This approach removes the need to dispatch an additional action to sync the url with the store like before, improving performance, and reduces complexity in the router when wanting to include a new component in a page.

Disadvantage: unreadble urls.

NOTE: I have left in some commented functions incase this approach is not approved to that we can comprise on some features.

Demo

Open up redux tools, and try the zoom buttons on the map.

Credit: pretty much @j8seangel's PR.

@edbrett edbrett requested review from pjosh and j8seangel July 3, 2018 15:35
Copy link
Contributor

@pjosh pjosh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very interesting approach! good job guys! 👏 👏

Copy link
Contributor

@j8seangel j8seangel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You got something really good 🌎 👏 , and very glad to help a bit here!

@@ -1,74 +0,0 @@
export const initialState = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

import { getMapSettings } from '../../map-selectors';

const mapStateToProps = ({ location }) => ({
settings: getMapSettings(location)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this working perfectly, we have to take a look here https://github.com/reduxjs/reselect#sharing-selectors-with-props-across-multiple-component-instances to be 100% sure.

@@ -44,8 +50,8 @@ class MapContainer extends PureComponent {
}

componentWillReceiveProps(nextProps) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be deprecated soon, why don't use componentDidUpdate instead?

@j8seangel
Copy link
Contributor

Loving the structure selector! Feel free to merge and thanks!

@edbrett edbrett merged commit 0bf6999 into feature/map-v2 Jul 5, 2018
@edbrett edbrett deleted the feature/map-routing branch July 5, 2018 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants