import Dexie from 'dexie'; import { initCreatingHook } from './hooks/creating'; import { initUpdatingHook } from './hooks/updating'; import { initDeletingHook } from './hooks/deleting'; export function initCrudMonitor(db: Dexie) { return function crudMonitor(table: Dexie.Table) { if (table.hook._dsyncObserving) { return; } table.hook._dsyncObserving = true; const tableName = table.name; table.hook('creating').subscribe(initCreatingHook(db, tableName)); table.hook('updating').subscribe(initUpdatingHook(db, tableName)); table.hook('deleting').subscribe(initDeletingHook(db, tableName)); }; }