Barry Gitarts c45893cf09 add LiquidModel
add with-observables
2019-01-18 12:03:17 -05:00

26 lines
771 B
JavaScript

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
}
}