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
feat(cmf): add two state static accessors #1371
feat(cmf): add two state static accessors #1371
Conversation
@jmfrancois what happen if i have multiple instance of this component ? how to deal with such situation ? |
…ub.com:Talend/ui into jmfrancois/feat/cmf/add-static-state-accessors
I have updated the doc to show you how |
1 similar comment
packages/cmf/src/cmfConnect.md
Outdated
@@ -221,6 +221,32 @@ If you want to render some component conditionally, just pass "renderIf" prop (t | |||
You can also use Expression for this and customize this prop like "renderIfExpression" in | |||
CMF json configuration files | |||
|
|||
## How to access state and mute from the outside |
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.
hi, by 'mute' do you mean 'mutate'?
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 think that is what he mean, but it is also misleading since the state is not mutated but updated with a non mutable operation.
## Read and update component state from outside
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.
👍
output/cmf.eslint.txt
Outdated
@@ -26,5 +32,5 @@ The react/require-extension rule is deprecated. Please use the import/extensions | |||
/home/travis/build/Talend/ui/packages/cmf/src/sagas/collection.js | |||
10:1 error Prefer default export import/prefer-default-export | |||
|
|||
✖ 12 problems (9 errors, 3 warnings) | |||
✖ 18 problems (15 errors, 3 warnings) | |||
|
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.
Hmm some cleaning maybe ;)
packages/cmf/src/cmfConnect.js
Outdated
static getState = function getState(state, id = 'default') { | ||
return state.cmf.components.getIn([getComponentName(WrappedComponent), id], defaultState); | ||
}; | ||
static setStateAction = function setStateAction(state, id = 'default', type) { |
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.
state parameter to be renamed newState i think
also shouldn't those state update operation also support synchronous state update function ? for safe state update operation when relying on previous state ?
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.
newState already exists in the upper declaration
I have added the asyn state update support
packages/cmf/src/cmfConnect.md
Outdated
@@ -221,6 +221,32 @@ If you want to render some component conditionally, just pass "renderIf" prop (t | |||
You can also use Expression for this and customize this prop like "renderIfExpression" in | |||
CMF json configuration files | |||
|
|||
## How to access state and mutate from the outside |
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.
title may be misleading, the state is not mutated in sense of pointer value mutation, but it is updated
to avoid confusion i would rename this title to
## Read and update component state from outside
…ub.com:Talend/ui into jmfrancois/feat/cmf/add-static-state-accessors
I need #1374 to let the tests pass |
What is the problem this PR is trying to solve?
Every time we need to modify a state from the outside (saga, actionCreator) we need to deal with a low level api (actions.component.mergeState).
That means the dev need to know and hard code the name of the component and this is not easy, error prone and not futur proof (add HOC case for example which change the name).
What is the chosen solution to this problem?
Expose two static functions:
Please check if the PR fulfills these requirements
[ ] This PR introduces a breaking change