Implement a new method to add multiple rows simultaneously without rerenders in-between the row additions
This commit is contained in:
parent
bb4c24329a
commit
8b488f488b
2 changed files with 28 additions and 4 deletions
|
|
@ -62,10 +62,14 @@ export class Database {
|
|||
};
|
||||
|
||||
// MARK: Row Ops
|
||||
static createRow(table, userID, row) {
|
||||
static createRow(table, userID, row, opts) {
|
||||
throw new Error(`createRow() must be implemented`);
|
||||
};
|
||||
|
||||
static createRows(table, userID, rows, opts) {
|
||||
throw new Error(`createRows() must be implemented`);
|
||||
};
|
||||
|
||||
static getRows(tableID, userIDs, privacy = `none`) {
|
||||
throw new Error(`getRows() must be implemented`);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { Database } from "./Database.mjs";
|
||||
import { filterPrivateRows } from "../filterPrivateRows.mjs";
|
||||
import { filterPrivateRows } from "../privacy.mjs";
|
||||
import { Logger } from "../Logger.mjs";
|
||||
|
||||
const { randomID, mergeObject } = foundry.utils;
|
||||
|
||||
|
|
@ -89,17 +90,36 @@ export class MemoryDatabase extends Database {
|
|||
return this.#tables[tableID];
|
||||
};
|
||||
|
||||
static createRow(table, userID, row) {
|
||||
static createRow(table, userID, row, { rerender = true } = {}) {
|
||||
if (!this.#tables[table]) { return };
|
||||
this.#rows[userID] ??= {};
|
||||
this.#rows[userID][table] ??= [];
|
||||
|
||||
// data format assertions
|
||||
row._id ||= randomID();
|
||||
row.timestamp = new Date().toISOString();
|
||||
|
||||
Logger.debug(`Adding row:`, row);
|
||||
this.#rows[userID][table].push(row);
|
||||
if (rerender) {
|
||||
this.render({ userUpdated: userID });
|
||||
};
|
||||
};
|
||||
|
||||
static createRows(table, userID, rows, { rerender = true } = {}) {
|
||||
if (!this.#tables[table]) { return };
|
||||
this.#rows[userID] ??= {};
|
||||
this.#rows[userID][table] ??= [];
|
||||
|
||||
// data format assertions
|
||||
for (const row of rows) {
|
||||
this.createRow( table, userID, row, { rerender: false } );
|
||||
};
|
||||
|
||||
if (rerender) {
|
||||
this.render({ userUpdated: userID });
|
||||
};
|
||||
};
|
||||
|
||||
static getRows(tableID, userIDs, privacy = `none`) {
|
||||
if (userIDs.length === 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue