diff --git a/src/data-provider.ts b/src/data-provider.ts index 603b677..0b1e9a5 100644 --- a/src/data-provider.ts +++ b/src/data-provider.ts @@ -17,9 +17,8 @@ const dataProvider = ({ dataModels, getSession }: DataProviderConfig) : DataProv }, create: async ({ resource, variables, meta }) => { console.log("create", resource, variables, meta); - + const session = getSession(); - console.log('session', session); const docNuri = await ng.doc_create( session!.session_id, @@ -93,12 +92,6 @@ const dataProvider = ({ dataModels, getSession }: DataProviderConfig) : DataProv } }, getApiUrl: () => "", - // optional methods - // getMany: ({ resource, ids, meta }) => Promise, - // createMany: ({ resource, variables, meta }) => Promise, - // deleteMany: ({ resource, ids, variables, meta }) => Promise, - // updateMany: ({ resource, ids, variables, meta }) => Promise, - // custom: ({ url, method, filters, sorters, payload, query, headers, meta }) => Promise, }); export default dataProvider; diff --git a/src/live-provider.ts b/src/live-provider.ts index 617d4b6..357285d 100644 --- a/src/live-provider.ts +++ b/src/live-provider.ts @@ -1,7 +1,6 @@ import { LiveProvider } from "@refinedev/core"; import { watch } from "@ng-org/alien-deepsignals" -import { getSignalObject } from "./utils"; -import { parsePatches } from "./utils"; +import { getSignalObject, parsePatches } from "./utils"; import { LiveProviderConfig, UnwatchFn } from "./types"; const liveProvider = ({ dataModels }: LiveProviderConfig) : LiveProvider => ({ @@ -40,8 +39,6 @@ const liveProvider = ({ dataModels }: LiveProviderConfig) : LiveProvider => ({ // We don't close the subscription because we want to keep listening for changes const set = await getSignalObject(dataModels[resource].shapeType, undefined, false); - console.log('set listening list', set); - const { stopListening } = watch(set, ({ newValue, patches }) => { console.log('objects list modified', newValue, patches); @@ -65,7 +62,7 @@ const liveProvider = ({ dataModels }: LiveProviderConfig) : LiveProvider => ({ return () => undefined; }, unsubscribe: async (unwatchFn: UnwatchFn | Promise) => { - console.log('unsubscribe', typeof unwatchFn, unwatchFn); + console.log('unsubscribe', unwatchFn); const fn = await Promise.resolve(unwatchFn); if (typeof fn === "function") { fn(); diff --git a/src/utils.ts b/src/utils.ts index fb7d973..a3844da 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -11,6 +11,7 @@ export const getSignalObject = async (shapeType: ShapeType, ids?: string[], return signalObject; } +// Return true if the key is a valid graph key (not a document) export const isGraphKey = (key: BaseKey): boolean => { return key !== null && typeof key === "string" && key.includes(":v:"); } @@ -22,6 +23,10 @@ export const addIdToObject = (obj: any) => { return { id: obj["@graph"], ...obj }; }; +/** + * Takes a list of patches (returned by the watch function) and returns a record of modified IDs + * with their corresponding event types (created, updated, deleted). + */ export const parsePatches = (patches: DeepPatch[]) => { let modifiedIds : Record = {};