Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
Enable portapi.js to revive query/subscriptions after reconnect by de…
Browse files Browse the repository at this point in the history
…fault
  • Loading branch information
dhaavi committed May 22, 2020
1 parent e8e8931 commit e44d2a0
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions assets/js/portapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Operation {
constructor(name, type) {
this.name = name;
this.type = type;
this.isGetReq = type == "get";
this.queryText = null;
this.record = null;
this.records = {};
this.loading = true;
Expand Down Expand Up @@ -44,7 +44,7 @@ class Operation {
}

// set new object
if (this.isGetReq) {
if (this.type == "get") {
// single object
this.record = obj;
this.prepRecord(key, this.record);
Expand Down Expand Up @@ -75,7 +75,7 @@ class Operation {
}
}
deleteRecord(key) {
if (this.isGetReq) {
if (this.type == "get") {
if (this.record) {
this.record._deleted = true; // mark deleted for copied references
}
Expand Down Expand Up @@ -236,6 +236,14 @@ function install(vue, options) {
console.log("sending queued request: " + requestText);
});
vue.portapi.requestQueue = [];

// refresh existing subscriptions
for (var request of Object.values(vue.portapi.requests)) {
if (request.queryText) {
vue.portapi.ws.send(request.queryText);
console.log("refreshing request: " + request.queryText);
}
}
};

vue.portapi.ws.onclose = function(event) {
Expand Down Expand Up @@ -375,6 +383,9 @@ function install(vue, options) {
var cleanedData = op.prepObjectForSubmission(data)
requestText += "|J" + JSON.stringify(cleanedData);
}
if (msgType == "sub" || msgType == "qsub") {
op.queryText = requestText;
}

if (vue.portapi.connected) {
if (vue.portapi.debug) console.log("sending request: " + requestText);
Expand Down

0 comments on commit e44d2a0

Please sign in to comment.