Skip to content

Commit fbe734c

Browse files
authored
Merge pull request #19 from GiacomoManzoli/master
Correctly calls `errorCallback` if there is only one request
2 parents 47242f8 + 922fcfb commit fbe734c

4 files changed

Lines changed: 5400 additions & 18 deletions

File tree

bimserverclient.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@ export class BimServerClient {
680680
if (showedBusy) {
681681
this.notifier.resetStatus();
682682
}
683+
errorsToReport.push(data.response.exception);
683684
}
684685
} else {
685686
if (showDone) {
@@ -701,8 +702,12 @@ export class BimServerClient {
701702
}
702703
});
703704
}
704-
if (errorsToReport.length > 0) {
705-
errorCallback(errorsToReport);
705+
if (errorsToReport.length > 0 && errorCallback) {
706+
if (requests.length == 1) {
707+
errorCallback(errorsToReport[0]); // with one request (and one error) -> call with an object
708+
} else {
709+
errorCallback(errorsToReport); // multiple requests, sends an array of errors
710+
}
706711
} else {
707712
if (requests.length == 1) {
708713
callback(data.response);

model.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ export class Model {
782782
};
783783

784784
types.forEach((type) => {
785-
if (this.loadedTypes[type] != null) {
785+
if (this.loadedTypes[type] && Object.getOwnPropertyNames(this.loadedTypes[type]).length !== 0) {
786786
for (let oid in this.loadedTypes[type]) {
787787
callback(this.loadedTypes[type][oid]);
788788
}
@@ -806,32 +806,30 @@ export class Model {
806806
serializerOid: serializer.oid
807807
});
808808
this.bimServerApi.getJson(url, null, (data) => {
809-
if (this.loadedTypes[type] == null) {
810-
this.loadedTypes[type] = {};
811-
}
812-
data.objects.some((object) => {
813-
if (this.objects[object._i] != null) {
809+
data.objects.forEach((object) => {
810+
if (this.objects[object._i]) {
814811
// Hmm we are doing a query on type, but some objects have already loaded, let's use those instead
815812
const wrapper = this.objects[object._i];
816813
if (wrapper.object._s == 1) {
817-
if (wrapper.isA(type)) {
818-
this.loadedTypes[type][object._i] = wrapper;
819-
return callback(wrapper);
814+
if (wrapper.isA(object._t)) {
815+
this.loadedTypes[object._t][object._i] = wrapper;
816+
callback(wrapper);
820817
}
821818
} else {
822819
// Replace the value with something that's LOADED
823820
wrapper.object = object;
824-
if (wrapper.isA(type)) {
825-
this.loadedTypes[type][object._i] = wrapper;
826-
return callback(wrapper);
821+
if (wrapper.isA(object._t)) {
822+
this.loadedTypes[object._t][object._i] = wrapper;
823+
callback(wrapper);
827824
}
828825
}
829826
} else {
830827
const wrapper = this.createWrapper(object, object._t);
831828
this.objects[object._i] = wrapper;
832-
if (wrapper.isA(type) && object._s == 1) {
833-
this.loadedTypes[type][object._i] = wrapper;
834-
return callback(wrapper);
829+
if (object._s == 1) {
830+
if (!this.loadedTypes[object._t]) { this.loadedTypes[object._t] = {} }
831+
this.loadedTypes[object._t][object._i] = wrapper;
832+
callback(wrapper);
835833
}
836834
}
837835
});

0 commit comments

Comments
 (0)