Skip to content

Commit 442ddc2

Browse files
author
Dennis Labordus
authored
Merge pull request #207 from com-pas/refactor-websocket-wrapper
Refactor of Websocket wrapper to use promise.
2 parents a40672e + c2db8c5 commit 442ddc2

12 files changed

+303
-433
lines changed

src/compas-editors/CompasVersions.ts

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export default class CompasVersionsPlugin extends LitElement {
109109
} else {
110110
const type = getTypeFromDocName(this.docName);
111111
CompasSclDataService()
112-
.listVersions(type, this.docId)
112+
.listSclVersions(type, this.docId)
113113
.then(xmlResponse => {
114114
this.historyItem = Array.from(
115115
xmlResponse.querySelectorAll('HistoryItem') ?? []
@@ -146,24 +146,11 @@ export default class CompasVersionsPlugin extends LitElement {
146146
return function () {
147147
const type = getTypeFromDocName(plugin.docName);
148148

149-
const service = CompasSclDataService();
150-
if (service.useWebsocket()) {
151-
service.getSclDocumentVersionUsingWebsockets(
152-
plugin,
153-
type,
154-
plugin.docId,
155-
version,
156-
(sclDocument) => {
157-
updateDocument(sclDocument);
158-
})
159-
} else {
160-
service
161-
.getSclDocumentVersionUsingRest(type, plugin.docId, version)
162-
.then(sclDocument => {
163-
updateDocument(sclDocument);
164-
})
165-
.catch(reason => createLogEvent(plugin, reason));
166-
}
149+
CompasSclDataService()
150+
.getSclDocumentVersion(plugin, type, plugin.docId, version)
151+
.then(updateDocument)
152+
.catch(reason => createLogEvent(plugin, reason));
153+
167154
// Close the Restore Dialog.
168155
plugin.dispatchEvent(newWizardEvent());
169156

@@ -372,29 +359,14 @@ export default class CompasVersionsPlugin extends LitElement {
372359

373360
private async getVersion(version: string): Promise<void | Element> {
374361
const type = getTypeFromDocName(this.docName);
375-
const service = CompasSclDataService();
376-
377-
if (service.useWebsocket()) {
378-
return new Promise((resolve) => {
379-
service.getSclDocumentVersionUsingWebsockets(
380-
this,
381-
type,
382-
this.docId,
383-
version,
384-
(sclDocument) => {
385-
resolve(sclDocument.documentElement);
386-
})
362+
return CompasSclDataService()
363+
.getSclDocumentVersion(this, type, this.docId, version)
364+
.then(sclDocument => {
365+
return Promise.resolve(<Element>sclDocument.documentElement);
366+
})
367+
.catch(reason => {
368+
createLogEvent(this, reason);
387369
});
388-
} else {
389-
return service
390-
.getSclDocumentVersionUsingRest(type, this.docId, version)
391-
.then(sclDocument => {
392-
return Promise.resolve(<Element>sclDocument.documentElement);
393-
})
394-
.catch(reason => {
395-
createLogEvent(this, reason)
396-
});
397-
}
398370
}
399371

400372
private openEditWizard(): void {

0 commit comments

Comments
 (0)