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 {fromJS} = require('immutable'); | |
| const data = fromJS({ name: 'gilbox' }); | |
| const rendererMixin = { | |
| getInitialState() { | |
| return {data:this.props.data} | |
| }, | |
| edit (transform) { | |
| this.setState({data: transform(this.state.data)}) | |
| } |
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 subedit = (edit, ...path) => transform => | |
| edit(state => state.updateIn(path, transform)); |
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 {fromJS} = require('immutable'); | |
| const data = fromJS({ name: 'gilbox' }); | |
| const Hello = component(function Hello ({name}, {edit}) { | |
| return <div> | |
| Hello, {name}! | |
| <button onClick={event => edit(data => data.updateIn(['name'], 'Maude Lebowski') }> | |
| Change My Name | |
| </button> | |
| </div> |
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 {fromJS} = require('immutable'); | |
| const data = fromJS({ name: 'gilbox' }); | |
| const Hello = component(function Hello ({name}, {edit}) { | |
| return <div> | |
| Hello, {name}! | |
| <button onClick={event => edit(name => 'Maude Lebowski') }> | |
| Change My Name | |
| </button> | |
| </div> |
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
| // @param additionalMixins? {Array|Object} | |
| // @param renderFn {Function} | |
| // @returns Component | |
| function component(additionalMixins, renderFn) { | |
| renderFn = renderFn || additionalMixins; | |
| additionalMixins = (additionalMixins instanceof Function) ? [] : [].concat(additionalMixins); | |
| const mixins = [ComponentRenderMixin].concat(additionalMixins); | |
| const render = function() { |
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
| // ComponentRenderMixin is a slightly modified version of PureRenderMixin | |
| const ComponentRenderMixin = require('component-render-mixin'); | |
| function delegate(delegee) { | |
| var delegate = function() { | |
| return delegate.delegee.apply(this, arguments); | |
| } | |
| delegate.delegee = delegee; | |
| delegate.isDelegate = true; | |
| return delegate; |
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 {fromJS} = Immutable; | |
| const subedit = (edit, ...path) => transform => | |
| edit(state => state.updateIn(path, transform)); | |
| const data = fromJS({ | |
| phone: '6665552222' | |
| }); | |
| const parsePhone = v => v.replace(/\D/g, '').substr(0,10); |
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
| @elegant | |
| class Hello extends Component { | |
| render() { | |
| const {name} = this.props; | |
| return <div>Hello, {name}!</div> | |
| } | |
| } |
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
| // @param additionalMixins? {Array|Object} | |
| // @param renderFn {Function} | |
| // @returns Component | |
| function component(additionalMixins, renderFn) { | |
| renderFn = renderFn || additionalMixins; | |
| additionalMixins = (additionalMixins instanceof Function) ? [] : [].concat(additionalMixins); | |
| const mixins = [ComponentRenderMixin, | |
| staticFunctionsMixin] | |
| .concat(additionalMixins); |
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 {shouldComponentUpdate} from '../component-render-mixin'; | |
| import {componentWillMount, componentWillReceiveProps} from '../statics-mixin'; | |
| function elegant(DecoratedComponent) { | |
| return class ElegantDecorator extends React.Component { | |
| static displayName = `Elegant(${getDisplayName(DecoratedComponent)})`; | |
| static DecoratedComponent = DecoratedComponent; | |
| shouldComponentUpdate(nextProps, nextState) { | |
| return shouldComponentUpdate.call(this, nextProps, nextState); |