Async init of cubeJsClient doesn't work with hot observable
- Dominant language
- Rust
- Stars
- 20.8k
- Forks
- 2.1k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 181
Description
Hey, I'm using CubeJs client for angular.
As others mentioned, a very common flow is to first verify the user and only then init cubeJs client with the config params.
I was following your example of dynamic angular dashboard (which is btw broken, it has the wrong version for cubejs-client\ngx in the package.json so the example wont compile), and I've noticed I'm getting a runtime error when I'm trying to call load() function.
After digging in the source code I found the problem :
1) Why do you need the ready$ at all? seems it always fires true event, even if config is null (which will throw an error later..)

2) If I use subject (or any other hot observable) as my observable, when the user uses any cubejs-client function, a runtime error gets thrown since when apiInstance() subscribes to config (which is hot observable) it will only receive the next event, which in turns make apiInstance() return undefined which then throws error when trying to call cubejs functions (load for example).

3) Even if config is cold observable and when the user calls some cubejs-client api function, if the value is null (the user has logged out for example), if this is the first time the user is trying to call the function - a runtime error gets thrown since config is null and the apiInistance() is trying to access config properties.
If this is not the first time, lets say the user used the app and logged out, the config will be null, and since an error was thrown the subscription is terminated, so even if the users logs back in, you cant instantiate new cubejs with the new token,


Here is the error I was getting:

My init function for async cubejs

Where currentAuthenticatedUser$ is hot observable (subject)
P.S: I can ( and have) fixed it on my end by adding shareReplay(1), so even late subscribers get the last event.
Thanks
Contributor guide
Assessment
This issue has not been assessed yet.