2020-03-03 21:02:13 +01:00
|
|
|
import {defaults, omitBy, isNil} from 'lodash'
|
2019-03-02 11:25:10 +01:00
|
|
|
|
|
|
|
export default class AbstractModel {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The abstract constructor takes an object and merges its data with the default data of this model.
|
|
|
|
* @param data
|
|
|
|
*/
|
|
|
|
constructor(data) {
|
|
|
|
// Put all data in our model while overriding those with a value of null or undefined with their defaults
|
|
|
|
defaults(this, omitBy(data, isNil), this.defaults())
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default attributes that define the "empty" state.
|
|
|
|
* @return {{}}
|
|
|
|
*/
|
|
|
|
defaults() {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
}
|