Skip to content

Commit

Permalink
Merge pull request umbraco#17928 from umbraco/v15/bugfix/fix-omitted-…
Browse files Browse the repository at this point in the history
…callback

Fix omitted callback
  • Loading branch information
nielslyngsoe authored Jan 10, 2025
2 parents 75e7bb4 + bd456a1 commit 7932eb9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
15 changes: 10 additions & 5 deletions src/Umbraco.Web.UI.Client/src/libs/class-api/class.mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,26 @@ export const UmbClassMixin = <T extends ClassConstructor<EventTarget>>(superClas
>(
// This type dance checks if the Observable given could be undefined, if it potentially could be undefined it means that this potentially could return undefined and then call the callback with undefined. [NL]
source: ObservableType,
callback: ObserverCallback<SpecificT>,
callback?: ObserverCallback<SpecificT>,
controllerAlias?: UmbControllerAlias | null,
): SpecificR {
// Fallback to use a hash of the provided method, but only if the alias is undefined.
controllerAlias ??= controllerAlias === undefined ? simpleHashCode(callback.toString()) : undefined;
// Fallback to use a hash of the provided method, but only if the alias is undefined and there is a callback.
if (controllerAlias === undefined && callback) {
controllerAlias = simpleHashCode(callback.toString());
} else if (controllerAlias === null) {
// if value is null, then reset it to undefined. Null is used to explicitly tell that we do not want a controller alias. [NL]
controllerAlias = undefined;
}

if (source) {
return new UmbObserverController<T>(
this,
source,
callback as unknown as ObserverCallback<T>,
callback as unknown as ObserverCallback<T> | undefined,
controllerAlias,
) as unknown as SpecificR;
} else {
callback(undefined as SpecificT);
callback?.(undefined as SpecificT);
this.removeUmbControllerByAlias(controllerAlias);
return undefined as SpecificR;
}
Expand Down
15 changes: 10 additions & 5 deletions src/Umbraco.Web.UI.Client/src/libs/element-api/element.mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,26 @@ export const UmbElementMixin = <T extends HTMLElementConstructor>(superClass: T)
>(
// This type dance checks if the Observable given could be undefined, if it potentially could be undefined it means that this potentially could return undefined and then call the callback with undefined. [NL]
source: ObservableType,
callback: ObserverCallback<SpecificT>,
callback?: ObserverCallback<SpecificT>,
controllerAlias?: UmbControllerAlias | null,
): SpecificR {
// Fallback to use a hash of the provided method, but only if the alias is undefined.
controllerAlias ??= controllerAlias === undefined ? simpleHashCode(callback.toString()) : undefined;
// Fallback to use a hash of the provided method, but only if the alias is undefined and there is a callback.
if (controllerAlias === undefined && callback) {
controllerAlias = simpleHashCode(callback.toString());
} else if (controllerAlias === null) {
// if value is null, then reset it to undefined. Null is used to explicitly tell that we do not want a controller alias. [NL]
controllerAlias = undefined;
}

if (source) {
return new UmbObserverController<T>(
this,
source,
callback as unknown as ObserverCallback<T>,
callback as unknown as ObserverCallback<T> | undefined,
controllerAlias,
) as unknown as SpecificR;
} else {
callback(undefined as SpecificT);
callback?.(undefined as SpecificT);
this.removeUmbControllerByAlias(controllerAlias);
return undefined as SpecificR;
}
Expand Down

0 comments on commit 7932eb9

Please sign in to comment.