title: CombineLatest of dynamic array inside switchMap is unsubscribing and re-subscribing continuously
body: <p>I have at least two buttons that I want to dynamically listen for clicks on. <code>listeningArray$</code> will emit an array (<code>ar</code>) of button #'s that I need to be listening to. When somebody clicks on one of these buttons I'm listening to, I need to console log that the button that was clicked and also log the value from a time interval. </p>
  
  <p>If <code>ar</code> goes from <code>[1,2]</code> to <code>[1]</code>, we need to stop listening to clicks on button #2. So the DOM click event needs to be removed for <code>2</code> and that should trigger the <code>.finally()</code> operator. But for <code>1</code>, we should remain subscribed and the code inside the <code>.finally()</code> should not run, since nothing is being unsubscribed. </p>
  
  <pre><code>const obj$ = {};
  
  Rx.Observable.combineLatest(
    Rx.Observable.interval(2000),
    listeningArray$ // Will randomly emit either [1] or [1,2]
  )
  .switchMap(([x, ar]) =&gt; {
      const observables = [];
  
      ar.forEach(n =&gt; {
          let nEl = document.getElementById('el'+n);
  
          obj$[n] = obj$[n] || Rx.Observable.fromEvent(nEl, 'click')
            .map(()=&gt;{
              console.log(' el' + n);
            })
            .finally(() =&gt; {
              console.log(' FINALLY_' + n);
            });
  
          observables.push(obj$[n]);
      })
  
      return Rx.Observable.combineLatest(...observables);
  })
  .subscribe()
  </code></pre>
  
  <p>But what's happening is every time the interval emits a value, the DOM events ALL get removed and then immediately get added on again, and the code inside the .finally operator runs for <code>1</code> <em>and</em> <code>2</code>.</p>
  
  <p>This is really frustrating me. What am I missing?</p>
  
  <p>It's a bit of a complex situation, so I created this: <a href="https://jsfiddle.net/mfp22/xtca98vx/7/" rel="nofollow noreferrer">https://jsfiddle.net/mfp22/xtca98vx/7/</a></p>