Fix #3456 action and reducer dev guide#3705
Conversation
* also pushed other minor fixes for other dev guide pieces
| @@ -1,5 +1,5 @@ | |||
| # Creating a MapStore2 plugin | |||
| The MapStore2 [plugins architecture](plugins-architecture) allows building your own idenpendent modules that will integrate seamlessly into your project. | |||
| The MapStore2 [plugins architecture](plugins-architecture) allows building your own inde pendent modules that will integrate seamlessly into your project. | |||
There was a problem hiding this comment.
| The MapStore2 [plugins architecture](plugins-architecture) allows building your own inde pendent modules that will integrate seamlessly into your project. | |
| The MapStore2 [plugins architecture](plugins-architecture) allows building your own independent modules that will integrate seamlessly into your project. |
|
|
||
| > ┻┳| | ||
| > ┳┻| _ | ||
| > ┻┳| •.•) 💬 *"Hey, Checkout this awesome documentation for actions and reducers!"* |
| ... | ||
| case UPDATE_LAYER_FEATURE: { | ||
| const indexFeatureChanged = findIndex(state.features, id => action.id) | ||
| const features = indexFeatureChanged !== -1 ? set([indexFeatureChanged], action.props, state.features) : state.features; |
There was a problem hiding this comment.
for this there is arrayUpdate :
Suggest the best function:
case UPDATE_LAYER_FEATURE: {
// lodash get
const feature = get(state.features, {id: action.id});
// merge the old and the new feature object, replacing the existing element in the array
return arrayUpdate("features", {...feature, action.props}, {id: action.id}, state);
}
There was a problem hiding this comment.
going to keep this and remove the other example
| ``` | ||
| Which is good but maybe less readable than using other ways. | ||
|
|
||
| We suggest to use lodash/fp which allows to avoid mutation of the objects (remember reducers are pure function) |
There was a problem hiding this comment.
Don't mention directly lodash/fp. This may confuse user learning both lodash and lodash/fp. I suggest to mention only ImmutableUtils and remand to documentation (adding it to docma-config)
I attach a version of ImmutableUtils that should be correctly documented
ImmutableUtils.txt
There was a problem hiding this comment.
ImmutableUtils is missing in the framework doc. i'm going to add it
(also many other Utils are missing)
| Which is good but maybe less readable than using other ways. | ||
|
|
||
| We suggest to use lodash/fp which allows to avoid mutation of the objects (remember reducers are pure function) | ||
| We have prepared some utilities in @mapstore/utils/ImmutableUtils like set |
There was a problem hiding this comment.
Set is best for single properties like loading or myFlag. If you want to mention set, please provide a example that fits.
For array manipluation there are other ImmutableUtils utilities
|
after the @mbarto review i'm gonna push some changes |
| } | ||
| }; | ||
| ``` | ||
| **Note** that SamplePlugin in plugins.js must be called with the same used when exporting it |
There was a problem hiding this comment.
Same what? Same name I suppose
| Note: to enable a plugin both requiring it in the plugins.js file and configuring it in localConfig.json is required. If one is missing, the plugin won't appear. | ||
| Note: to enable a plugin you need to do two things: | ||
| - require it in the plugins.js file | ||
| - configure it in localConfig.json is required. (just remove the Plugins suffix here) |
There was a problem hiding this comment.
configure it in localConfig.json (remove the Plugin suffix here)
| Again quoting redux [documentation](https://redux.js.org/basics/reducers) they are: | ||
| > Reducers specify how the application's state changes in response to actions sent to the store. | ||
|
|
||
| Reducers are pure function that takes the previous state and an action and returns a new state |
There was a problem hiding this comment.
Reducers are pure functions that take the previous state and an action and return a new state
| // @mapstore is an alias for dir_name/web/client (see webpack.config.js) | ||
| import {PAN_TO} from '@mapstore/actions/map'; | ||
|
|
||
| export function map( (state, action) => { |
There was a problem hiding this comment.
The syntax is not correct, either use function syntax or arrow functions syntax
| **Note:** Remember to put all the reducers .js files in the web/client/reducers folder or in js/reducers if you are working with custom plugins | ||
|
|
||
| ## Advanced usage and tips | ||
| Sometimes you need to change a value of an item which is store inside an array or in a nested object. |
There was a problem hiding this comment.
Sometimes you need to change a value of an item which is stored inside an array or in a nested object.
|
|
||
| We use [expect](https://github.com/mjackson/expect) as testing library, therefore we suggest to have a look there. | ||
|
|
||
| ## How to test and action |
| This allows to run only the tests contained to the specified path. | ||
| **Note:** When all tests are successfully passing remember to restore it to its orignal value '../web' | ||
|
|
||
| ## How to test an reducer |
offtherailz
left a comment
There was a problem hiding this comment.
Please test docma before to merge
Description
This pr add actions and reducers documentation
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)
actions and reducer dev documentation was missing
What is the new behavior?
not anymore
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:
I noticed that some links are not working because they point to missing doc files.
like this one