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

Fixes #3454 plugins developers documentation - round 2 #3512

Merged
merged 5 commits into from
Mar 6, 2019

Conversation

mbarto
Copy link
Contributor

@mbarto mbarto commented Feb 6, 2019

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)

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • [ x Other... Please describe: documentation

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)

  • Yes
  • No

If this PR contains a breaking change, please describe the impact and migration path for existing applications: ...

Other information:

@ghost ghost assigned mbarto Feb 6, 2019
@mbarto mbarto added this to the 2019.02.00 milestone Feb 6, 2019
@mbarto mbarto requested a review from offtherailz February 6, 2019 17:26
@mbarto mbarto assigned allyoucanmap and unassigned allyoucanmap Feb 6, 2019
@mbarto mbarto requested a review from allyoucanmap February 6, 2019 17:26
@@ -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
Copy link
Member

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?

Copy link
Contributor Author

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".

Copy link
Member

@offtherailz offtherailz Feb 21, 2019

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:

  1. 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.

  2. 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
);

Copy link
Member

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 😆 ?

@mbarto mbarto merged commit c7d0f7c into geosolutions-it:dev_guide Mar 6, 2019
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