liquid-funding/app/utils/models.js

26 lines
771 B
JavaScript
Raw Normal View History

2019-01-18 17:03:17 +00:00
import { Model } from '@nozbe/watermelondb'
export function getFields(obj) {
const validTypes = new Set(['string', 'number', 'boolean'])
const newObj = {}
const proto = Object.getPrototypeOf(obj)
const names = Object.getOwnPropertyNames(proto)
names
.filter(name => validTypes.has(typeof obj[name]))
.forEach(name => { newObj[name] = obj[name] })
return newObj
}
export class LiquidModel extends Model {
getFields() {
const validTypes = new Set(['string', 'number', 'boolean'])
const newObj = {}
const proto = Object.getPrototypeOf(this)
const names = Object.getOwnPropertyNames(proto)
names
.filter(name => validTypes.has(typeof this[name]))
.forEach(name => { newObj[name] = this[name] })
return newObj
}
}