diff --git a/frontend/src/global/item-list.ts b/frontend/src/global/item-list.ts deleted file mode 100644 index d70ac169..00000000 --- a/frontend/src/global/item-list.ts +++ /dev/null @@ -1,21 +0,0 @@ -import ldChannel from '../common-rdf/radio'; -import Collection from '../core/collection'; -import { nodeListFactory, parseResponse, userNodesFactory } from '../utilities/prefetch-utilities'; -import ItemGraph from '../common-adapters/item-graph'; - - -const itemList = new Collection(); -itemList.parse = parseResponse; -const getNodeList = nodeListFactory(); - -const userItems = new ItemGraph(); -const getUserNodes = userNodesFactory(); - - -/** - * Registering our services with the radio channel. - */ -ldChannel.once('cache:item-list', () => getNodeList(itemList, true)); -ldChannel.reply('promise:item-list', () => getNodeList(itemList, true)); -ldChannel.once('cache:user-items', () => getUserNodes(userItems, true)); -ldChannel.reply('promise:user-items', () => getUserNodes(userItems, true)); diff --git a/frontend/src/global/source-list.ts b/frontend/src/global/source-list.ts deleted file mode 100644 index 7b08ff1d..00000000 --- a/frontend/src/global/source-list.ts +++ /dev/null @@ -1,20 +0,0 @@ -import Collection from '../core/collection'; -import ItemGraph from '../common-adapters/item-graph'; -import ldChannel from '../common-rdf/radio'; -import { source } from '../common-rdf/ns'; -import { parseResponse, nodeListFactory, userNodesFactory } from '../utilities/prefetch-utilities'; - -const sourceList = new Collection(); -sourceList.parse = parseResponse; -const getNodeList = nodeListFactory(); - -const userSources = new ItemGraph(source()); -const getUserNodes = userNodesFactory(); - -/** - * Registering our services with the radio channel. - */ -ldChannel.once('cache:source-list', () => getNodeList(sourceList, false)); -ldChannel.reply('promise:source-list', () => getNodeList(sourceList, false)); -ldChannel.once('cache:user-sources', () => getUserNodes(userSources, false)); -ldChannel.reply('promise:user-sources', () => getUserNodes(userSources, false)); diff --git a/frontend/src/utilities/prefetch-utilities.ts b/frontend/src/utilities/prefetch-utilities.ts deleted file mode 100644 index b437975e..00000000 --- a/frontend/src/utilities/prefetch-utilities.ts +++ /dev/null @@ -1,70 +0,0 @@ -import {sparqlRoot} from 'config.json'; -import ItemGraph from '../common-adapters/item-graph'; - -import Collection from '../core/collection'; - -import { countNodesQuery, nodesByUserQuery } from "../sparql/compile-query"; - -/** - * a utility function to ensure that each getUserNodes function uses its own promise - * @returns getUserNodes function, with its own promise object - */ -export function userNodesFactory() { - let promise: PromiseLike = null; - - function getUserNodes(userNodes: ItemGraph, queryingItems: boolean): PromiseLike { - if (!promise) { - const query = nodesByUserQuery(queryingItems); - promise = userNodes.sparqlQuery(query).then( - () => handleSuccess(userNodes), handleError - ); - } - return promise; - } - - function handleSuccess(userNodes): ItemGraph { - promise = Promise.resolve(userNodes); - return userNodes; - } - - function handleError(error: any): any { - promise = Promise.reject(error); - return error; - } - - return getUserNodes; -} - -export function nodeListFactory() { - let promise: PromiseLike = null; - - function getNodeList(queriedList: Collection, queryingItems: boolean): PromiseLike { - if (!promise) { - const query = countNodesQuery(queryingItems); - const endpoint = queryingItems ? 'item/query' : 'source/query' - promise = queriedList.fetch({ - url: sparqlRoot + endpoint, - data: $.param({ query: query }), - remove: false - }).then(() => handleSuccess(queriedList), handleError); - } - return promise; - } - - function handleSuccess(queriedList): Collection { - promise = Promise.resolve(queriedList); - return queriedList; - } - - function handleError(error: any): any { - promise = Promise.reject(error); - return error; - } - - return getNodeList; -} - - -export function parseResponse(response): [] { - return response.results.bindings.map( node => node.node ); -}