Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="combineLatest operator">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <script src="https://unpkg.com/@reactivex/rxjs@5.0.3/dist/global/Rx.js"></script>
</head>
<body>
<input id="inputA" type="text"><button id="A">A</button>
<input id="inputB" type="text"><button id="B">B</button>
  <ol>
  <li>Enter a value for Field A and then click Button A to register value</li>
    <li>Enter a value for Field B and then click Button B to register value</li>
    <li>After both value are emitted, repeat step 1 and 2 to see how combineLatest work</li>
  </ol>
    </body>
</html>
 
const getValue = (id) => document.getElementById(`input${id}`).value
const clickEvent = (id) => Rx.Observable
                             .fromEvent(
                                 document.getElementById(id),'click', ()=> getValue(id)
                             )
const unsubscribe = Rx.Observable
                    .fromEvent(
                      document.getElementById("end"), 'click', ()=> console.log('end clicked')
                    )
const streamA = clickEvent('A');
const streamB = clickEvent('B');
const combineLatest = Rx.Observable
                        .combineLatest(streamA, streamB)
                        .subscribe(
                          combined => console.log('combinedLatest', combined)
                        )
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
kkennethleepro
0viewers