Created
April 4, 2017 02:02
-
-
Save kaievns/aae9450b041e8e36ce3c1ef49b01e032 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 connect = (mapStateToProps, mapDispatchToProps) => magic ... | |
const MegaLopolos = (props) => | |
<div> | |
Stuff.... | |
</div> | |
export defaults connect(mapStateToProps, mapDispatchToProps)(cssModules(styles)(MegaLopolos)); | |
@connect(mapStateToProps, mapDispatchToProps) | |
@cssModules(styles) | |
@somethingElse() | |
export default class MegaLopolos extends React.Component { | |
render() { | |
return <div>Stuff...</div> | |
} | |
} | |
@cssModules(styles) | |
class Blah extends React.Component { | |
@logger() | |
render() { | |
return ( | |
<div styleName="blah"> | |
blahsh | |
</div> | |
) | |
} | |
} | |
new Blah().render(); | |
function logger(options) { | |
return function(target) { | |
return function() { | |
console.log('calling render'); | |
target.apply(this, arguments); | |
console.log('called renderd'); | |
} | |
} | |
} | |
const mapStateToProps = (state, props) => ({ stuff }); | |
const mapDispatchToProps = (dispatch) => ({ | |
save(data) { return disaptch(someAction(data)); } | |
}) | |
@connect(mapStateToProps, mapDispatchToProps) | |
class MyComponent extends React.Component { | |
submit() { | |
} | |
render() { | |
const { stuff, save } = this.props; | |
return <div> blah .... </div>; | |
} | |
}; | |
function connect(mapStateToProps, mapDispatchToProps) { | |
return function(OriginalComponent) { | |
return class WrapperComponent extends React.Component { | |
// submit() { | |
// | |
// } | |
render() { | |
const { store } = this.context; | |
const dataProps = mapStateToProps(store.getState(), this.props) | |
const actionProps = mapDispatchToProps(store.dispatch); | |
dataProps -> { stuff } | |
actionProps -> { save(data) } | |
this.wrappedInstance = <OriginalComponent {...dataProps} {...actionProps} {...this.props} />; | |
return this.wrappedInstance; | |
} | |
} | |
} | |
} | |
<Provider store={store}> // context | |
<WrapperComponent ref="myStuff"/> | |
this.refs.myStuff.wrappedInstance.submit(); | |
</Provider> | |
class Stuff extends React.Component { | |
handler = (event) => { | |
const { input } = this.refs; | |
input.value... | |
} | |
render() { | |
return <input | |
type="text" | |
name="blah" | |
ref={instance => this.refs.input = instance} | |
ref="instance" | |
onChange={this.handler} /> | |
const instance = new input({ | |
type: 'text', | |
name: 'blah', | |
onChange: this.handler | |
}); | |
return instance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment