ngxtension / ngxtension-platform

Utilities for Angular
https://ngxtension.netlify.app/
MIT License
591 stars 87 forks source link

`derivedFrom`: cannot provide `undefined` as `initialValue` #427

Open mattmoos opened 3 months ago

mattmoos commented 3 months ago

I noticed that an initial value of undefined cannot be used in derivedFrom. I think this would be okay in itself because Angular is using undefined implicitly as initial value. But derivedFrom is setting requireSync: true when it detects no initial value, cf. https://github.com/ngxtension/ngxtension-platform/blob/658830c2fa6dc9eaf9f8e813c0509f9d8b5064bf/libs/ngxtension/derived-from/src/derived-from.ts#L112 and that does not work with async observables as sources

The problem seems to be here: https://github.com/ngxtension/ngxtension-platform/blob/658830c2fa6dc9eaf9f8e813c0509f9d8b5064bf/libs/ngxtension/derived-from/src/derived-from.ts#L135 derivedFrom is checking options?.initialValue !== undefined;, thus an initial value of undefined gets lost.

I guess this could be fixed by using Object.hasOwn(options, 'initialValue') instead?

eneajaho commented 3 months ago

@mattmoos Can you provide a PR that adds a test case with your usecase (simplified) that breaks, and we can work on a fix or just use what you recommended (object.hasOwn).

mattmoos commented 3 months ago

Yes, just had a look at the existing test cases. I think I can provide a test.