Only initialize IDBShim and database once

This commit is contained in:
Hamcha 2019-09-12 11:20:06 +02:00
parent e238485b21
commit cf47d5db4a
Signed by: hamcha
GPG key ID: 44AD3571EB09A39E
3 changed files with 17 additions and 4 deletions

View file

@ -20,8 +20,10 @@ class CardDatabase extends Dexie {
export let Database: CardDatabase | null = null; export let Database: CardDatabase | null = null;
export function initDB() { export function initDB() {
if (Database == null) {
Database = new CardDatabase(); Database = new CardDatabase();
} }
}
export async function getCards(filter: CardFilter) { export async function getCards(filter: CardFilter) {
if (Database == null) { if (Database == null) {

11
src/testing/IDBShim.ts Normal file
View file

@ -0,0 +1,11 @@
import Dexie from "dexie";
let init = false;
export function setupIDBShim() {
if (!init) {
const setGlobalVars = require("indexeddbshim");
setGlobalVars(Dexie.dependencies);
init = true;
}
}

View file

@ -1,7 +1,7 @@
import { loadSets, getCards, Database, initDB, cardFullName } from "@/mlpccg"; import { loadSets, getCards, Database, initDB, cardFullName } from "@/mlpccg";
import Dexie from "dexie"; import { setupIDBShim } from "@/testing/IDBShim";
const setGlobalVars = require("indexeddbshim");
setGlobalVars(Dexie.dependencies); setupIDBShim();
describe("mlpccg/Database", () => { describe("mlpccg/Database", () => {
beforeAll(async () => { beforeAll(async () => {