UNPKG

lincd

Version:

LINCD is a JavaScript library for building user interfaces with linked data (also known as 'structured data', or RDF)

44 lines 1.67 kB
import { useEffect } from 'react'; import { QueryShape } from './SelectQuery.js'; import { Shape } from '../shapes/Shape.js'; import { TestNode } from '../utils/TraceShape.js'; const queryContext = new Map(); export function useQueryContext(name, initialData, shapeType) { useEffect(() => { setQueryContext(name, initialData, shapeType); }, [initialData, name]); } export function getQueryContext(name) { if (!queryContext.has(name)) { //TODO:should return something here so that the query still works and returns default values // like NullQueryShape or similar return null; } return queryContext.get(name); } export function setQueryContext(name, value, shapeType) { //if a QResult was provided if (value && (typeof value.id === 'string' || typeof value.uri === 'string')) { //convert to QShape if (!shapeType) { console.warn('setQueryContext: value is a QResult but no shapeType provided', value); return; } const testNode = new TestNode(); testNode.targetID = value.id || value.uri; const shape = new shapeType(testNode); //.getFromURI(value.id); value = QueryShape.create(shape); //const converted = QueryBuilderObject.convertOriginal(shape,null,null); } if (value instanceof Shape) { //convert to QShape value = new QueryShape(value); } else if (value && !(value instanceof QueryShape)) { console.warn('setQueryContext: value is not a QueryShape or Shape', value); return; } queryContext.set(name, value); } //# sourceMappingURL=QueryContext.js.map