Skip to content

Fix #3456 action and reducer dev guide#3705

Merged
MV88 merged 4 commits intogeosolutions-it:masterfrom
MV88:3456_actions_reducers
May 2, 2019
Merged

Fix #3456 action and reducer dev guide#3705
MV88 merged 4 commits intogeosolutions-it:masterfrom
MV88:3456_actions_reducers

Conversation

@MV88
Copy link
Copy Markdown
Contributor

@MV88 MV88 commented Apr 24, 2019

Description

This pr add actions and reducers documentation

  • also pushed other minor fixes for other dev guide pieces

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
  • Other... Please describe: documentation

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)

  • Yes, and I documented them in migration notes
  • No

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

* also pushed other minor fixes for other dev guide pieces
@MV88 MV88 added the Dev Guide label Apr 24, 2019
@MV88 MV88 added this to the 2019.02.00 milestone Apr 24, 2019
@MV88 MV88 requested review from mbarto and offtherailz April 24, 2019 13:14
@MV88 MV88 self-assigned this Apr 24, 2019
@coveralls
Copy link
Copy Markdown

coveralls commented Apr 24, 2019

Coverage Status

Coverage increased (+0.06%) to 81.267% when pulling 947d80a on MV88:3456_actions_reducers into aeb28d5 on geosolutions-it:master.

@@ -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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
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!"*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

cute

...
case UPDATE_LAYER_FEATURE: {
const indexFeatureChanged = findIndex(state.features, id => action.id)
const features = indexFeatureChanged !== -1 ? set([indexFeatureChanged], action.props, state.features) : state.features;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

@MV88 MV88 Apr 29, 2019

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

@MV88
Copy link
Copy Markdown
Contributor Author

MV88 commented Apr 29, 2019

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How to test an 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How to test a reducer

@tdipisa tdipisa modified the milestone: 2019.02.00 Apr 29, 2019
Copy link
Copy Markdown
Member

@offtherailz offtherailz left a comment

Choose a reason for hiding this comment

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

Please test docma before to merge

@MV88 MV88 merged commit d54158b into geosolutions-it:master May 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dev Guide - Writing actions and reducers

5 participants