Skip to content

Commit

Permalink
Added a subscribe function to the DataSync QueryBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed Jan 27, 2022
1 parent 051bb26 commit ccac5f7
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/IHP/DataSync/ihp-querybuilder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DataSyncController } from './ihp-datasync.js';
import { DataSyncController, DataSubscription } from './ihp-datasync.js';

function fetchAuthenticated(path, params) {
const jwt = localStorage.getItem('ihp_jwt');
Expand Down Expand Up @@ -82,6 +82,12 @@ class QueryBuilder {
const result = await this.limit(1).fetch();
return result.length > 0 ? result[0] : null;
}

subscribe(callback) {
const dataSubscription = new DataSubscription(this.query);
dataSubscription.createOnServer();
return dataSubscription.subscribe(callback)
}
}

function query(table) {
Expand Down

0 comments on commit ccac5f7

Please sign in to comment.