infor-cloud / m3-h5-sdk

https://infor-cloud.github.io/m3-h5-sdk/
34 stars 20 forks source link

MIService executes HTTP request without subscription #148

Open cdasilvacosta opened 1 year ago

cdasilvacosta commented 1 year ago

Hello I have created a generic component that takes an observable as input and launches it only when I need it (to gain performance). When I call api through the HttpClient of angular, it works very well. But when I use the MIService execute, I see that the M3 api calls run without any subscription on it. Very simple example :

@Component({
   templateUrl: './test.component.html'
})
export class TestComponent implements OnInit {

   constructor(private miService: MIService) {
   }

   ngOnInit(): void {
      this.miService.execute({
         program: 'MNS150MI',
         transaction: 'LstUserData'
      })

   }
}

image

I looked at how the MIService was developed. From the moment the "execute" method is called, it executes the http request directly and stores the result in an observable. This can become very problematic and even generate big performance problems.

anhallbe commented 1 year ago

Yes! This is indeed a bug. But fixing it may be considered a breaking change, as some existing application may depend on requests being fired without a subscribe(), since that is the way it has always worked.

Will look into this.

But in the meantime, as a workaround you could defer the execution. Example (not tested):

import { defer } from "rxjs";

// This should not fire the request
const response$ = defer(() => this.miService.execute({
    program: 'MNS150MI',
    transaction: 'LstUserData',
}));

// This fires the request
response$.subscribe(response => ...)
cdasilvacosta commented 1 year ago

Thanks for the answer.

Why not make a major update just to avoid that it impacts the current projects and report this correction in the release notes?

swuendri commented 1 year ago

@anhallbe and @cdasilvacosta, I have prepared a PR #153.