| 8 | class Model extends React.Component { |
| 9 | |
| 10 | constructor(props) { |
| 11 | super(props) |
| 12 | const { name, schema, modelKey, initialValues, props: modelProps } = props |
| 13 | |
| 14 | const model = name ? this.getModel(name, modelKey, modelProps) : { |
| 15 | ...schema, |
| 16 | key: modelKey || schema.name, |
| 17 | ...modelProps |
| 18 | } |
| 19 | let initial = initialValues |
| 20 | if(!initial && model.initialValues) { |
| 21 | initial = _.isFunction(model.initialValues) ? model.initialValues() : model.initialValues |
| 22 | } |
| 23 | app.context.store.dispatch({ type: 'INITIALIZE', model, initial }) |
| 24 | this.state = { model } |
| 25 | } |
| 26 | |
| 27 | getModel(name, key, props) { |
| 28 | const model = app.get('models')[name] |