Fixed not overriding null values
All checks were successful
the build was successful

This commit is contained in:
konrad 2019-02-20 21:03:13 +01:00
parent 07f954978f
commit 3e6a5b4e2d
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 3 additions and 15 deletions

View File

@ -1,10 +1,10 @@
import {defaults} from "lodash";
import {defaults, omitBy, isNil} from "lodash";
export default class AbstractModel {
constructor(data) {
// Put all data in our model
defaults(this, data, this.defaults())
// 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.

View File

@ -4,15 +4,7 @@ export default class ListModel extends abstractModel {
constructor(data) {
super(data)
// Set the tasks to [] if its empty so we can add tasks
// FIXME: need a better solution for this (aka properly setting defaults
if(this.tasks === null) {
this.tasks = []
}
this.sortTasks()
// eslint-disable-next-line
console.log(this)
}
// Default attributes that define the "empty" state.
@ -30,10 +22,6 @@ export default class ListModel extends abstractModel {
}
}
getTitle() {
return this.title;
}
sortTasks() {
if (this.tasks === null || this.tasks === []) {
return