datalovelace/src/Models/Tables.js
ysandler ab29b45a4e refact: replace dmein with lovelacejs
its the same thing just a new npm name
2020-07-31 18:08:44 -05:00

39 lines
871 B
JavaScript

import { Table } from 'lovelacejs'
import { uuid } from 'uuidv4'
let instance = null
class Tables {
constructor () {
if (!instance) instance = this
this.collection = []
return instance
}
addNewTable = table => {
try {
const newTable = new Table({
id: table.id || uuid(),
label: table.label,
rows: table.rows
})
this.collection.push(newTable)
} catch (err) {
console.error(err)
}
}
removeById = id => {
const indexToRemove = this.collection.findIndex(t => t.id === id)
if (indexToRemove > -1) this.collection.splice(indexToRemove, 1)
}
getCollectionProps = () => this.collection.map(table => table.getProperties())
getById = id => this.collection.find(t => id === t.id)
getTableByLabel = label => this.collection.find(t => label === t.label)
}
export default Tables