Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor of Websocket wrapper to use promise. #207

Merged
merged 3 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 13 additions & 41 deletions src/compas-editors/CompasVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default class CompasVersionsPlugin extends LitElement {
} else {
const type = getTypeFromDocName(this.docName);
CompasSclDataService()
.listVersions(type, this.docId)
.listSclVersions(type, this.docId)
.then(xmlResponse => {
this.historyItem = Array.from(
xmlResponse.querySelectorAll('HistoryItem') ?? []
Expand Down Expand Up @@ -146,24 +146,11 @@ export default class CompasVersionsPlugin extends LitElement {
return function () {
const type = getTypeFromDocName(plugin.docName);

const service = CompasSclDataService();
if (service.useWebsocket()) {
service.getSclDocumentVersionUsingWebsockets(
plugin,
type,
plugin.docId,
version,
(sclDocument) => {
updateDocument(sclDocument);
})
} else {
service
.getSclDocumentVersionUsingRest(type, plugin.docId, version)
.then(sclDocument => {
updateDocument(sclDocument);
})
.catch(reason => createLogEvent(plugin, reason));
}
CompasSclDataService()
.getSclDocumentVersion(plugin, type, plugin.docId, version)
.then(updateDocument)
.catch(reason => createLogEvent(plugin, reason));

// Close the Restore Dialog.
plugin.dispatchEvent(newWizardEvent());

Expand Down Expand Up @@ -372,29 +359,14 @@ export default class CompasVersionsPlugin extends LitElement {

private async getVersion(version: string): Promise<void | Element> {
const type = getTypeFromDocName(this.docName);
const service = CompasSclDataService();

if (service.useWebsocket()) {
return new Promise((resolve) => {
service.getSclDocumentVersionUsingWebsockets(
this,
type,
this.docId,
version,
(sclDocument) => {
resolve(sclDocument.documentElement);
})
return CompasSclDataService()
.getSclDocumentVersion(this, type, this.docId, version)
.then(sclDocument => {
return Promise.resolve(<Element>sclDocument.documentElement);
})
.catch(reason => {
createLogEvent(this, reason);
});
} else {
return service
.getSclDocumentVersionUsingRest(type, this.docId, version)
.then(sclDocument => {
return Promise.resolve(<Element>sclDocument.documentElement);
})
.catch(reason => {
createLogEvent(this, reason)
});
}
}

private openEditWizard(): void {
Expand Down
Loading