In my current project, I am facing a challenge where multiple events can be triggered from an object. These events are handled by a component and then sent to a REST API. The issue arises when I need to ensure that calls to the REST API for a specific resource are made in sequence. For example, I have the following methods:
someObjectCreated(objectCreated){
this.http.post(...);
}
someObjectNameChanged(objectNameChanged){
this.http.post(...);
}
someObjectDeleted(objectDeleted){
this.http.delete(...);
}
These event handler methods can be executed at any time. Consider a scenario where someObjectCreated is called, followed immediately by someObjectNameChanged before the POST of someObjectCreated has even completed.
I am wondering if there is a way to chain the outcomes of these observables. Would it be more efficient to convert them to promises and chain them using .then()? Are there any common design patterns in Angular that can help solve this problem?