2af53b16b6
Only include needed parts from lodash Don't prefetch Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/288 Co-Authored-By: konrad <konrad@kola-entertainments.de> Co-Committed-By: konrad <konrad@kola-entertainments.de>
33 lines
No EOL
808 B
JavaScript
33 lines
No EOL
808 B
JavaScript
import defaults from 'lodash/defaults'
|
|
import isNil from 'lodash/isNil'
|
|
import omitBy from 'lodash/omitBy'
|
|
import {objectToCamelCase} from '@/helpers/case'
|
|
|
|
export default class AbstractModel {
|
|
|
|
/**
|
|
* The max right the user has on this object, as returned by the x-max-right header from the api.
|
|
* @type {number|null}
|
|
*/
|
|
maxRight = null
|
|
|
|
/**
|
|
* The abstract constructor takes an object and merges its data with the default data of this model.
|
|
* @param data
|
|
*/
|
|
constructor(data) {
|
|
|
|
data = objectToCamelCase(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 {}
|
|
}
|
|
} |