I read the documentation of switchMap and map, but I still don\'t completely understand the difference. Are there some cases where it does not make a difference at all?
see the definitions of 2 functions:
map(syncFunction: (input: inputType) => outputType )
switchmap>( asyncFunction: (input: inputType) => Observable )
map = an asynchronous function calls a synchronous function (asyncTask => syncTask)
switchMap = an asynchronous function calls an asynchronous function sequentially (asyncTask => asyncTask )
example for switchMap:
observable1 calls observable2 means:
observable1_event1 => new observable2 asynchronous => Task1
observable1_event2 => new observable2 asynchronous => Task2
observable1_event3 ...
If observable1_event2 is emitted when task1 is not completed, the Observable2 of task1 will be rejected by calling unsubscribe(). It means Task1 will not show output any more after that.
If observable1_event2 is emmitted when task1 was completed. all outputs of Task1 will be showed normally then outputs of task2 will be showed.
Note that: each new observable2 can trigger many events (observable2_event1, observable2_event2,...)