Skip to content

Commit 7932eb9

Browse files
authored
Merge pull request #17928 from umbraco/v15/bugfix/fix-omitted-callback
Fix omitted callback
2 parents 75e7bb4 + bd456a1 commit 7932eb9

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/Umbraco.Web.UI.Client/src/libs/class-api/class.mixin.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,26 @@ export const UmbClassMixin = <T extends ClassConstructor<EventTarget>>(superClas
5353
>(
5454
// 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]
5555
source: ObservableType,
56-
callback: ObserverCallback<SpecificT>,
56+
callback?: ObserverCallback<SpecificT>,
5757
controllerAlias?: UmbControllerAlias | null,
5858
): SpecificR {
59-
// Fallback to use a hash of the provided method, but only if the alias is undefined.
60-
controllerAlias ??= controllerAlias === undefined ? simpleHashCode(callback.toString()) : undefined;
59+
// Fallback to use a hash of the provided method, but only if the alias is undefined and there is a callback.
60+
if (controllerAlias === undefined && callback) {
61+
controllerAlias = simpleHashCode(callback.toString());
62+
} else if (controllerAlias === null) {
63+
// if value is null, then reset it to undefined. Null is used to explicitly tell that we do not want a controller alias. [NL]
64+
controllerAlias = undefined;
65+
}
6166

6267
if (source) {
6368
return new UmbObserverController<T>(
6469
this,
6570
source,
66-
callback as unknown as ObserverCallback<T>,
71+
callback as unknown as ObserverCallback<T> | undefined,
6772
controllerAlias,
6873
) as unknown as SpecificR;
6974
} else {
70-
callback(undefined as SpecificT);
75+
callback?.(undefined as SpecificT);
7176
this.removeUmbControllerByAlias(controllerAlias);
7277
return undefined as SpecificR;
7378
}

src/Umbraco.Web.UI.Client/src/libs/element-api/element.mixin.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,26 @@ export const UmbElementMixin = <T extends HTMLElementConstructor>(superClass: T)
2929
>(
3030
// 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]
3131
source: ObservableType,
32-
callback: ObserverCallback<SpecificT>,
32+
callback?: ObserverCallback<SpecificT>,
3333
controllerAlias?: UmbControllerAlias | null,
3434
): SpecificR {
35-
// Fallback to use a hash of the provided method, but only if the alias is undefined.
36-
controllerAlias ??= controllerAlias === undefined ? simpleHashCode(callback.toString()) : undefined;
35+
// Fallback to use a hash of the provided method, but only if the alias is undefined and there is a callback.
36+
if (controllerAlias === undefined && callback) {
37+
controllerAlias = simpleHashCode(callback.toString());
38+
} else if (controllerAlias === null) {
39+
// if value is null, then reset it to undefined. Null is used to explicitly tell that we do not want a controller alias. [NL]
40+
controllerAlias = undefined;
41+
}
3742

3843
if (source) {
3944
return new UmbObserverController<T>(
4045
this,
4146
source,
42-
callback as unknown as ObserverCallback<T>,
47+
callback as unknown as ObserverCallback<T> | undefined,
4348
controllerAlias,
4449
) as unknown as SpecificR;
4550
} else {
46-
callback(undefined as SpecificT);
51+
callback?.(undefined as SpecificT);
4752
this.removeUmbControllerByAlias(controllerAlias);
4853
return undefined as SpecificR;
4954
}

0 commit comments

Comments
 (0)