Skip to content

trackRequestResult - not responding when using take(1) within the pipe #534

@haythem-ouederni

Description

@haythem-ouederni

Which @ngneat/elf-* package(s) are the source of the bug?

Don't known / other

Is this a regression?

No

Description

Hello,
When trackRequestResult with a take(1) some after in the pipe, the second time we call the pipe containing all of it no result is returned.

Here is a example of the structure of a method calling trackRequestResult:

myFunction(): Observable<string> {
    return of(void 0).pipe(
      mergeMap(() => // any call to a webservice for eample),
     tap((resultFromWs) => // update the elf store with the result),
     trackRequestResult([uniqueID], {cacheResponseData: true}),
     mergeMap(() => // return the result from the store)
  )
}

And somewhere else in the code we call myFunction() as follow:

myFunction().pipe(take(1)).subscribe(() => {
   // do things
})

When myFunction is called for the first time we have the result returned. But after the first call, and from anywhere in the code, nothing happens.

If have quickly taken a look at the code source of trackRequestResult and I think that is comes from the use of complete within the tap. It is known that the complete is not called when the observable is "unsubscribed".

This is very unfortunate since the functionality is very helpful.

Do you think is it possible to replace the complete with a finalize that should resolve the problem ?

Thanks

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw


Please provide the environment you discovered this bug in

angular 17

"@ngneat/elf": "^2.5.1",
"@ngneat/elf-cli-ng": "^1.0.0",
"@ngneat/elf-devtools": "^1.3.0",
"@ngneat/elf-entities": "^4.5.0",
"@ngneat/elf-requests": "^1.9.2",

Anything else?

No response

Do you want to create a pull request?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions