import { reduce, filter, map, mapTo } from 'rxjs/operators'
import { from, fromEvent, scan, Subscription } from 'rxjs'
const button1 = document.getElementById("but1")
const button2 = document.getElementById("but2")
const button3 = document.getElementById("but3")
let click1 = fromEvent(button1, 'click')
.subscribe(result => {
count3.subscribe(x => p3.innerHTML = `Click count: ${x}`)
})
let click2 = fromEvent(button2, 'click')
here i want to unsubscribe subscription (when i click on second button, but with opportunity to subscribe again when i click first button)
I've tried with something like this
const sub = click1.subscribe(result => {
count3.subscribe(x => p3.innerHTML = `Click count: ${x}`)
})
let click2 = fromEvent(button2, 'click')
sub.unsubscribe()
But I don't know how to put sub.unsubscribe() into button
let click3 = fromEvent(button3, 'click')
let three = click3.pipe(mapTo(1))
let c: number = 0
let count3 = three.pipe(scan((acc, val) => acc + val, c))
const d = document.getElementById("d")
const p3 = document.createElement("p")
//count3.subscribe(x => p3.innerHTML = `Click count: ${x}`)
d?.appendChild(p3)