-
Notifications
You must be signed in to change notification settings - Fork 410
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
Fixes #3454 plugins developers documentation - round 2 #3512
Conversation
@@ -330,6 +647,7 @@ Notice that also container related properties can be overridden in the applicati | |||
* Selectors | |||
* use existing selectors when possible to connect the state, eventually using reselect to compose them together or with your own selectors | |||
* define new selectors only if you use them more than once and move them to a selectors JS file |
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.
I should suggest to put the selectors in the global file anyway, with common best practices of code reuse.
In my opinion they should be state access interface, that increases testability, stability, maintainability and so on.
We of course have to distinguish between selectors that access to common state parts and selectors that map state to specific plugin properties.
The latters should be in the plugin.
What do you think?
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.
I do not agree, putting anything in separate files decreases readability of the code, so we should put them in a separate file only when they are really shared.
Code re-use literally means "more than one use".
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.
I understand your point. please take into account also the following considerations:
-
When you develop a plugin, to understand if your selector already exists you have to look at all the plugins you think can have a similar behavior instead of look at the selector's file of the state splice you want to read. This of course encourages duplication. Instead having a file of already done function encourages the reuse of them.
-
Having the logic to access to the global state parts in the plugins decrease readability:
See this (not real) example of a tool that for epsg4326, if feature info is disabled, do geocoding on click :
This is what you propose
connect( () => createSelector(
state => state.map && state.map.projection && state.map.prolection === "EPSG:4326",
state => state.controls && state.controls.featureinfo && !state.controls.featureinfo.enabled ,
state => state.geocoder && state.geocoder.services && state.geocoder.services.length > 0,
(isCompatibleProjection, isFeatureInfoDisabled) => ({
myProp: isCompatibleProjection && isFeatureInfoDisabled
}))
I think this version is more readable, hiding the state access complexity
connect( () => createSelector(
isGeocodingEnabled,
enabled => ({enabled}) // map to your props
)
this in selectors/geocoder.js:
/**
* Check if the geocoder tool should be enabled (it is enabled only for EPSG:4326, when at least
* one service is available and feature info has not been activated
*/
const isGeocodingEnabled = createSelector(
state => state.map && state.map.projection && state.map.projection === "EPSG:4326",
state => state.controls && state.controls.featureinfo && !state.controls.featureinfo.enabled,
state => state.geocoder && state.geocoder.services && state.geocoder.services.length > 0,
(isCompatibleProjection, isFeatureInfoDisabled, hasServices) => isCompatibleProjection && FeatureInfoDisabled && hasServices
);
This:
- easy to document and test
- ready for reuse
- easy to maintain
- easy to refactor
- With all the selectors in the same file you can quickly identify duplications and parts that can be reused inside the same selector. The above selector can be easly converted into
const isEnabled = createSelector(
state => projectionSelector(state) === "EPSG:4326", // from selectors/map.js
state => !isControlEnabled("featureinfo")(state), // from controls
state => servicesSelector(state).length > 0 // inside this file,
(isCompatibleProjection, isFeatureInfoDisabled, hasServices) => isCompatibleProjection && FeatureInfoDisabled && hasServices
);
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.
Does it means I convinced you or you're going to shoot me a rocket 😆 ?
Description
Second round of developers documentation for plugins-
Issues
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (check one with "x", remove the others)
What is the current behavior? (You can also link to an open issue here)
Incomplete plugins documentation
What is the new behavior?
More complete plugins documentation
Does this PR introduce a breaking change? (check one with "x", remove the other)
If this PR contains a breaking change, please describe the impact and migration path for existing applications: ...
Other information: