Skip to content

Instantly share code, notes, and snippets.

@theKashey
Last active January 26, 2018 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theKashey/766de5a95e1ad00feb7880edd793cc43 to your computer and use it in GitHub Desktop.
Save theKashey/766de5a95e1ad00feb7880edd793cc43 to your computer and use it in GitHub Desktop.
Why not?
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>
);
@theKashey
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment