matheo / angular

Open Source Angular Libraries: MatDataSource, MatDatepicker
http://matheo.co/demos/
MIT License
60 stars 15 forks source link

Optional streams act as though they are required. #41

Closed dsbert closed 2 years ago

dsbert commented 2 years ago

Describe the bug

Thanks for this library.

I may not fully understand the meaning of optional streams as it is not well documented. However, I would expect the first data request to be initiated without waiting for an optional stream to emit. Right now it seems that the optional streams must emit some value before the first data request will occur.

Adding the following operator to connect() in datasource-stream.ts does make the data source work as I would expect it to.

before

      optional.length
        ? merge(...optional).pipe(scan(this.reducePartials, {} as Partial<T>))
        : of({} as Partial<T>),

after

optional.length
        ? merge(...optional).pipe(
            startWith({}),
            scan(this.reducePartials, {} as Partial<T>),
          )
        : of({} as Partial<T>),

Minimal Reproduction

I don't have a fully reproducible example right now but I can create one at some point if it will help.

A simple data source with the following stream added

    this.addStream({
      name: 'filter',
      stream: form.valueChanges,
      optional: true,
    });

Expected behavior

The data source should automatically process the first data request.

Screenshots

If applicable, add screenshots to help explain your problem.

Your Environment

Angular Version:





Anything else relevant?

matheo commented 2 years ago

@dsbert Hi Daniel, thanks for the report and sorry the late answer. you're right, for some reason in my applications it worked as expected and I didn't realize this error in the logic.

I've also added a throttleTime to prevent subsequent triggers :) you can use @matheo/datasource@11.2.8 or @matheo/datasource@12.10.0-beta.0 Thanks again!