Skip to content

Instantly share code, notes, and snippets.

@dtothefp
Last active December 6, 2015 05:00
Show Gist options
  • Save dtothefp/afe40387a77dba7ac170 to your computer and use it in GitHub Desktop.
Save dtothefp/afe40387a77dba7ac170 to your computer and use it in GitHub Desktop.
@provideContextAsProps({
Actions: PropTypes.object.isRequired,
Getters: PropTypes.object.isRequired,
moreStuff: PropTypes.object,
stuffFromParent: PropTypes.func.isRequired
})
@nuclearComponent((props) => {
const {someChildProps, stuffFromParent, Getters, Actions} = props;
stuffFromParent(someChildProps, (arg) => {
if (arg && arg === 'whatevs') {
Actions.CoolActions.doSomethingCool(arg);
} else {
Actions.DumbActions.doSomethingDumb(someChildProps);
}
})
return {
someDataBinding: Getters.coolGetters.someState,
someLameBinding: Getters.dumbGetters.someState
}
})
class Child extends Component {
render() {
return <div>Child</div>
}
}
@provideReactor({
Actions: PropTypes.object.isRequired,
Getters: PropTypes.object.isRequired,
moreStuff: PropTypes.object
})
@nuclearComponent((props) => {
return {
whatevs: this.props.Getters.coolGetters.something
}
})
class TopLevel extends Component {
static childContextTypes = {
stuffFromParent: PropTypes.func
};
getChildContext() {
return {
stuffFromParent(childData, cb) {
if (childData.whatevs) {
cb('whatevs');
} else {
cb();
}
}
};
}
render() {
return (
<div>
<Child />
</div>
);
}
}
const CoolActions = makeCoolActions(reactor);
const DumbActions = makeDumbActions(reactor);
const coolGetters = CoolGetters('someKey');
const dumbGetters = DumbGetters('someKey');
ReactDom.render((
<TopLevel
reactor={reactor}
Actions={Object.assign({}, {CoolActions, DumbActions})}
Getters={Object.assign({}, {coolGetters, dumbGetters})}
MoreStuff={{whatevs: 'whatevs'}}
/>
), document.querySelector('[data="whatevs"]'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment