Last active
January 26, 2018 21:15
-
-
Save theKashey/766de5a95e1ad00feb7880edd793cc43 to your computer and use it in GitHub Desktop.
Why not?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { connect } from 'react-redux'; | |
import reduxSemaphore from 'react-redux-semaphore'; | |
import reduxFocus from 'react-redux-focus'; | |
// a + b = c. That a LAW! | |
const AddLaw = ({a, b, sum}) => <div>{a} + {b} = {sum}</div> | |
// ok, we will connect this component to a Redux store to get a data. Why not? | |
const ConnectedRender = connect( | |
({a, b, sum}) => ({a, b, sum}) | |
)(RenderAdd); | |
// Just double check that we did not bypass the law | |
const WillPropagateStateOnlyIfConditionMet = reduxSemaphore( | |
({a, b, sum}) => (a + b) === sum | |
)(ConnectedRender); | |
// MapStateToProps? MapPropToState! | |
const MapPropsToStore = reduxFocus( | |
(store, props) => ({...props}) | |
)(WillPropagateStateOnlyIfConditionMet); | |
// what happends next? | |
const App = ({a, b, sum}) => ( | |
<Provider store={store1}> | |
<PropsToStore a={a} b={b} sum={sum}/> | |
</Provider> | |
); | |
// in other words | |
const TestApp = (props) => ( | |
<ReduxFocus | |
focus={(state, props) => ({...props})} | |
{...props} | |
> | |
<ReduxSemaphore condition={({a, b, sum}) => ({a, b, sum})}> | |
<ConnectedRender/> | |
</ReduxSemaphore> | |
</ReduxFocus> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.npmjs.com/package/react-redux-semaphore