(ComposedComponent)
| 9 | export const COMPONENTS = {}; |
| 10 | |
| 11 | export const enhance = (ComposedComponent) => { |
| 12 | class FormItem extends Component { |
| 13 | constructor (props) { |
| 14 | super(props); |
| 15 | |
| 16 | this.state = { |
| 17 | hasError: false, |
| 18 | value: getValue(props) |
| 19 | }; |
| 20 | |
| 21 | this.valueType = getValueType(props.type); |
| 22 | this.handleChange = this.handleChange.bind(this); |
| 23 | } |
| 24 | |
| 25 | componentWillMount () { |
| 26 | const { itemBind } = this.props; |
| 27 | |
| 28 | if (itemBind) { |
| 29 | const value = getValue(this.props); |
| 30 | this.bindToForm(this.props, value); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | componentDidMount () { |
| 35 | let component = this.component; |
| 36 | if (!component) { |
| 37 | return; |
| 38 | } |
| 39 | Object.keys(component).forEach((key) => { |
| 40 | if (!this.hasOwnProperty(key)) { |
| 41 | let func = component[key]; |
| 42 | if (typeof func === 'function') { |
| 43 | this[key] = func; |
| 44 | } |
| 45 | } |
| 46 | }); |
| 47 | } |
| 48 | |
| 49 | componentWillReceiveProps (nextProps) { |
| 50 | let { name, value, formData, itemUnbind } = nextProps; |
| 51 | |
| 52 | if (nextProps.type && nextProps.type !== this.props.type) { |
| 53 | this.valueType = getValueType(nextProps.type); |
| 54 | } |
| 55 | |
| 56 | if (formData) { |
| 57 | value = formData[name]; |
| 58 | |
| 59 | if (this.props.name !== name && itemUnbind) { |
| 60 | itemUnbind(this.id, this.props.name); |
| 61 | this.bindToForm(nextProps, value); |
| 62 | } |
| 63 | |
| 64 | if (value !== this.state.value) { |
| 65 | this.handleChange(value, nextProps); |
| 66 | } |
| 67 | } else { |
| 68 | if (value !== this.props.value && value !== this.state.value) { |
no outgoing calls
no test coverage detected
searching dependent graphs…