fix(core): improve loaded/unloaded handling to be stable and consistent (#10170)

This commit is contained in:
Nathan Walker
2023-01-15 19:49:28 -08:00
committed by GitHub
parent a69a9d6921
commit c9e29aa9af
12 changed files with 121 additions and 166 deletions

View File

@@ -291,22 +291,24 @@ export class Observable implements ObservableDefinition {
}
for (let i = observers.length - 1; i >= 0; i--) {
const entry = observers[i];
if (entry.once) {
observers.splice(i, 1);
}
if (entry) {
if (entry.once) {
observers.splice(i, 1);
}
let returnValue;
if (entry.thisArg) {
returnValue = entry.callback.apply(entry.thisArg, [data]);
} else {
returnValue = entry.callback(data);
}
let returnValue;
if (entry.thisArg) {
returnValue = entry.callback.apply(entry.thisArg, [data]);
} else {
returnValue = entry.callback(data);
}
// This ensures errors thrown inside asynchronous functions do not get swallowed
if (returnValue && returnValue instanceof Promise) {
returnValue.catch((err) => {
console.error(err);
});
// This ensures errors thrown inside asynchronous functions do not get swallowed
if (returnValue && returnValue instanceof Promise) {
returnValue.catch((err) => {
console.error(err);
});
}
}
}
}