This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
2020-03-03 20:02:13 +00:00
|
|
|
import {defaults, omitBy, isNil} from 'lodash'
|
2020-04-14 20:46:27 +00:00
|
|
|
import {objectToCamelCase} from '../helpers/case'
|
2019-03-02 10:25:10 +00: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) {
|
2020-04-14 20:46:27 +00:00
|
|
|
|
|
|
|
data = objectToCamelCase(data)
|
|
|
|
|
2019-03-02 10:25:10 +00:00
|
|
|
// 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 {}
|
|
|
|
}
|
|
|
|
}
|