Clean up
This commit is contained in:
@@ -19,7 +19,6 @@ const dataProvider = ({ dataModels, getSession }: DataProviderConfig) : DataProv
|
|||||||
console.log("create", resource, variables, meta);
|
console.log("create", resource, variables, meta);
|
||||||
|
|
||||||
const session = getSession();
|
const session = getSession();
|
||||||
console.log('session', session);
|
|
||||||
|
|
||||||
const docNuri = await ng.doc_create(
|
const docNuri = await ng.doc_create(
|
||||||
session!.session_id,
|
session!.session_id,
|
||||||
@@ -93,12 +92,6 @@ const dataProvider = ({ dataModels, getSession }: DataProviderConfig) : DataProv
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
getApiUrl: () => "",
|
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;
|
export default dataProvider;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { LiveProvider } from "@refinedev/core";
|
import { LiveProvider } from "@refinedev/core";
|
||||||
import { watch } from "@ng-org/alien-deepsignals"
|
import { watch } from "@ng-org/alien-deepsignals"
|
||||||
import { getSignalObject } from "./utils";
|
import { getSignalObject, parsePatches } from "./utils";
|
||||||
import { parsePatches } from "./utils";
|
|
||||||
import { LiveProviderConfig, UnwatchFn } from "./types";
|
import { LiveProviderConfig, UnwatchFn } from "./types";
|
||||||
|
|
||||||
const liveProvider = ({ dataModels }: LiveProviderConfig) : LiveProvider => ({
|
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
|
// We don't close the subscription because we want to keep listening for changes
|
||||||
const set = await getSignalObject(dataModels[resource].shapeType, undefined, false);
|
const set = await getSignalObject(dataModels[resource].shapeType, undefined, false);
|
||||||
|
|
||||||
console.log('set listening list', set);
|
|
||||||
|
|
||||||
const { stopListening } = watch(set, ({ newValue, patches }) => {
|
const { stopListening } = watch(set, ({ newValue, patches }) => {
|
||||||
console.log('objects list modified', newValue, patches);
|
console.log('objects list modified', newValue, patches);
|
||||||
|
|
||||||
@@ -65,7 +62,7 @@ const liveProvider = ({ dataModels }: LiveProviderConfig) : LiveProvider => ({
|
|||||||
return () => undefined;
|
return () => undefined;
|
||||||
},
|
},
|
||||||
unsubscribe: async (unwatchFn: UnwatchFn | Promise<UnwatchFn>) => {
|
unsubscribe: async (unwatchFn: UnwatchFn | Promise<UnwatchFn>) => {
|
||||||
console.log('unsubscribe', typeof unwatchFn, unwatchFn);
|
console.log('unsubscribe', unwatchFn);
|
||||||
const fn = await Promise.resolve(unwatchFn);
|
const fn = await Promise.resolve(unwatchFn);
|
||||||
if (typeof fn === "function") {
|
if (typeof fn === "function") {
|
||||||
fn();
|
fn();
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ export const getSignalObject = async (shapeType: ShapeType<any>, ids?: string[],
|
|||||||
return signalObject;
|
return signalObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return true if the key is a valid graph key (not a document)
|
||||||
export const isGraphKey = (key: BaseKey): boolean => {
|
export const isGraphKey = (key: BaseKey): boolean => {
|
||||||
return key !== null && typeof key === "string" && key.includes(":v:");
|
return key !== null && typeof key === "string" && key.includes(":v:");
|
||||||
}
|
}
|
||||||
@@ -22,6 +23,10 @@ export const addIdToObject = (obj: any) => {
|
|||||||
return { id: obj["@graph"], ...obj };
|
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[]) => {
|
export const parsePatches = (patches: DeepPatch[]) => {
|
||||||
let modifiedIds : Record<string, 'created' | 'updated' | 'deleted'> = {};
|
let modifiedIds : Record<string, 'created' | 'updated' | 'deleted'> = {};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user