Skip to content

Commit

Permalink
Use native js modules for exposing DataSync functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed Nov 20, 2021
1 parent 341a584 commit 7fb708b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/IHP/static/vendor/ihp-datasync-react.js
@@ -1,8 +1,11 @@
import React, { useState, useEffect } from 'react';
import { DataSubscription } from './ihp-datasync';

// Usage:
//
// const messages = useQueryResult(query('messages').orderBy('createdAt'));
//
function useQueryResult(queryBuilder) {
export function useQueryResult(queryBuilder) {
const [records, setRecords] = useState(null);

useEffect(() => {
Expand Down
4 changes: 3 additions & 1 deletion lib/IHP/static/vendor/ihp-datasync.js
@@ -1,4 +1,3 @@
// TODO: reconnect websocket if connection dies
class DataSyncController {
static getInstance() {
if (!window.dataSyncController) {
Expand Down Expand Up @@ -211,3 +210,6 @@ function initIHPBackend({ host }) {
}
window.ihpBackendHost = host;
}


export { DataSyncController, DataSubscription, initIHPBackend };
4 changes: 3 additions & 1 deletion lib/IHP/static/vendor/ihp-querybuilder.js
Expand Up @@ -194,4 +194,6 @@ async function deleteRecordById(table, id, patch) {

throw new Error(response.statusText);
}
}
}

export { QueryBuilder, query, createRecord, createRecords, updateRecordById, deleteRecordById };

0 comments on commit 7fb708b

Please sign in to comment.