-
Notifications
You must be signed in to change notification settings - Fork 1
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
Refactor using React Leaflet and React best practices #113
Conversation
Fixes Promise.defer error
react-router 3.2.0 is required for react 16.2; fails with react-router 2.0.1
This solves a weird webpack css-loader error as well as simplifying the app's dependencies and the code.
under control of prop 'oldschool'
These components establish a minimal but comparable framework for experimenting with react-leaflet etc. independently of the full app. Test app is rendered under control of a Boolean variable, currently hardcoded but could be otherwise controlled.
src/HOCs/compAcontrolsB.js
Outdated
// HOC. | ||
// Code fragment: | ||
// | ||
// ButtonWithModal = buttonWithModal(this.A, this.B); |
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.
Oops: ButtonWithModal = buttonWithModal(this.A, this.B)
--> AcontrollingB = compAcontrolsB(this.A, this.B)
src/index.js
Outdated
</Route> | ||
</Router> | ||
), document.getElementById('wrapper')); | ||
} |
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.
Undo: Outdated test harness
As you say, @jameshiebert , there is still a way to go on the refactoring; MapController in particular. I'd like every component to be quite simple and small. |
Testing it now. It looks really great! I'm only finding tiny things, some of which probably predate this refactor.
Also found an intermittent Dual Controller bug related switching ensembles and querying the |
This eliminates a lot of repetitive setting of props by passing the object instead of all properties separately
Refactor map controller state
@corviday thanks for the testing and review. The problems you noted are pre-existing; see the current production deploy. Also, my changes are confined to MapController subtree, so it is highly unlikely I modified any behaviour of the graphing side of things. |
Overview
Resolves #112
This is a big one! Apologies; I intended to break this down into several incremental PRs. But as noted in the associated issue, the old code and React Leaflet-based solutions turned out not to play well together, i.e., not at all. This forced a fully componentized refactoring, rather than a hybrid approach.
Isolation of changes
This branch replaces
MapController
and its descendants with refactored code.MapContoller
and its child components and supporting code.area
).MapController
and its co-conspiratorCanadaMap
have been removed and replaced by the newMapController
and its cast of new supporting components.Questions and suggestions for reviewers
I think it might make sense to review more or less top-down, starting with
AppController
/DualController
/MotiController
, which renderMapController
, which contains the big changes.AppController
/DualController
/MotiController
area
to beAppMixin
), prop everywhere elseDataController
MapController
MapController
andCanadaMap
into React-Leaflet and React components that are composed here (user-selection components rendered as children ofDataMap
).loadMap
andcomponentWillReceiveProps
. I'm preparing some questions and suggestions on refactoring this properly but I think there are enough changes already that this should be left for a follow-up PR. Essence of the questions/suggestions:dataset
and having the selector return the index into it. But this is part of the cleanup ofloadMap
andcomponentWillReceiveProps
.DataMap
NcWMSColorbarControl
s andNcWMSAutosetColorscaleControl
controls are dependent on their siblingDataLayer
s. Since they are rendered as sibling components (and can't be otherwise, without rewriting the React LeafletWMSTileLayer
component), their existence relative to each other is asynchronous, and that asynchrony has to be (or at least is most simply) coordinated by storing refs to the DataLayers on state.area
controls and layer up toAltMapController
? It doesn't do anything at this level, and isn't directly concerned with DataMap's primary purpose, which is the data map. That would make this a really crisp component.CanadaBaseMap
L.Proj.CRS
for our kind of tile layers. See the comments to that.crs
,version
,srs
,origin
not be props, just constants. I can't see how they can be useful as props. Am I missing something?DataLayer
NcWMSColorbarControl
LeafletNcWMSColorbarControl
layer
argument is null.L.DomUtil
.NcWMSAutosetColorscaleControl
LeafletNcWMSAutosetColorscaleControl
src/HOCs/compAcontrolsB
MapSettings
compAcontrolsB
. Button opens dialog.DatasetSelector
MapSettings
.MapSettingsDialog
DataDisplayControls
MapSettings
for both raster and isoline layers.TimeLinkButton
MapSettings
TimeSelector
MapSettings
.PaletteSelector
MapSettings
.ScaleSelector
MapSettings
.GeoLoader
compAcontrolsB
. Button opens main GeoLoader dialog.GeoLoaderDialogWithError
compAcontrolsB
. Error on loading opens error dialog.GeoExporter
compAcontrolsB
. Button opens GeoExporter dialog.MapFooter
Known issues
colorscalerange
. What's really needed is a clear spec of the desired behaviour.react-loader
is not compatible with React 16.npm install
emits warnings. But it works fine. No actual issue here.Principles and best practices followed
propTypes
. (*Except if you are passing through gobs of options to React Bootstrap components. Don't declare those ones unless you are feeling masochistic.)constructor
. (*No exceptions. Initialize tonull
orundefined
if necessary.)The end result of this is a kind of splitting of components into two types, with little mixing of the qualities of the two.
Note: "Wiring up" state and props is tedious, bulky, and repetitive. Which is why tools like Flux and Redux were invented. But we should stick with a bit of tediousness for now. Those tools come with their own complexity and tediousness.
Overview of the new componentization
The following is a compact distillation of the new components: