Skip to content

Instantly share code, notes, and snippets.

@zerkalica
Created August 6, 2015 11:58
Show Gist options
  • Save zerkalica/dafbcb4dfdd23a7b4119 to your computer and use it in GitHub Desktop.
Save zerkalica/dafbcb4dfdd23a7b4119 to your computer and use it in GitHub Desktop.
immutable-di-examples
import {default as React, Component} from 'react';
import {Getter, Facet, Factory, Setter} from 'immutable-di/define'
import root from 'immutable-di/react/root'
import statefull from 'immutable-di/react/statefull'
import Container from 'immutable-di'
import NativeCursor from 'immutable-di/cursors/native'
const container = new Container(new NativeCursor({
tis: {
a: 1,
b: 2
}
}));
var abbaFacet = Facet({
a: ['tis', 'a']
})(function bloomyFacet({a}) {
return a + 10;
})
var ChangeAction = Factory({
setA: Setter(['tis', 'a'])
})(function ({setA}) {
return function (num) {
setA(num);
}
});
@root
@statefull({
abba: abbaFacet,
changeAction: ChangeAction
})
class Application extends React.Component {
handleClick () {
this.props.changeAction(100);
}
render () {
return <div onClick={this.handleClick.bind(this)}>Bloom: {this.props.abba}</div>
}
}
export default function () {
React.render(<Application container={container} />, document.querySelector('.app'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment