Last active
February 20, 2016 16:56
-
-
Save dtothefp/3f2289aa2cd6c5be4500 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const daisyChain = ( | |
| <DaisyChain | |
| reactor={reactor} | |
| Actions={Actions} | |
| Getters={Getters} | |
| analytics={analytics} | |
| daisyChainId={daisyChainId} | |
| legacy | |
| > | |
| <EmailSignupForm ctaId={ctaId} /> | |
| <SingleIssueForm ctaId={ctaId} > | |
| </DaisyChain> | |
| ); | |
| ReactDOM.render( | |
| daisyChain, | |
| document.querySelector(selectors) | |
| ); |
This file contains hidden or 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
| const compToRender = ( | |
| <Wrapper | |
| reactor={reactor} | |
| Actions={Actions} | |
| analytics={analytics} | |
| legacy | |
| > | |
| <div class="o-wrap-content"> | |
| <SignupForm /> | |
| <SingleIssueForm /> | |
| </div> | |
| <DaisyChain /> | |
| </Wrapper> | |
| ); | |
| ReactDOM.render(compToRender, '[data-some-element]'); |
This file contains hidden or 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
| export default function(YourCtaComponent, dataBindingsFn) { | |
| static contextTypes = { | |
| reactor: PropTypes.object.isRequired | |
| }; | |
| constructor(props, context) { | |
| super(props); | |
| const {reactor} = context; | |
| //this is the object you return from `nuclearComponent` decorator | |
| const dataBindings = this.dataBindings = dataBindingsFn(props); | |
| const yourStoreState = Object.keys(dataBindings).reduce((acc, propKey) => { | |
| const keyPath = dataBindings[propKey]; | |
| //evaluates your initial state in the store | |
| acc[propKey] = reactor.evaluate(keyPath); | |
| return acc; | |
| }, {}); | |
| this.state = yourStoreState; | |
| } | |
| componentDidMount() { | |
| const {reactor} = this.context; | |
| Object.keys(this.dataBindings).forEach(propKey => { | |
| const keyPath = this.dataBindings[propKey]; | |
| //setup observation of the store, unfortunately components `didMount` get's called from the inside out | |
| //ie. child => parent so if you decide to emit an action in the `child` `constructor` or `componentDidMount` | |
| //then state will get out of sync and that action will not trigger this `reactor.observe` state update | |
| reactor.observe(keyPath, (changedValFromStore) => { | |
| const newState = Object.assign({}, this.state, { | |
| [propKey]: changeValFromStore | |
| }); | |
| this.setState(newState); //this updates Higher Order Component's state and causes re-render passing state as props to child | |
| }); | |
| }); | |
| } | |
| render() { | |
| const mergedProps = Object.assign({}, this.props, this.context, this.state); | |
| return <YourCtaComponent {...mergedProps} />; | |
| } | |
| } |
This file contains hidden or 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 {provideContextProps} from '@hfa/form-components/lib/config'; | |
| import {provideReactor} from 'nuclear-js-react-addons'; | |
| const ComponentToRender = provideReactor(SignupForm, provideContextProps); | |
| const comp = ( | |
| <ComponentToRender | |
| reactor={reactor} | |
| Actions={Actions} | |
| analytics={analytics} | |
| legacy | |
| /> | |
| ); | |
| ReactDOM.render(comp, someDomNode); |
This file contains hidden or 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
| @provideReactor(provideContextProps) | |
| class Wrapper extends Component { | |
| static propTypes = { | |
| children: PropTypes.array.isRequired | |
| }; | |
| render() { | |
| <div> | |
| {this.props.children} | |
| </div> | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment