Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <div>
    <div>Seconds spent typing: <span class="timer">0</span></div>
    <input type="text" id="input">
    <div class="typing"></div>
  </div>
  <script src="https://code.jquery.com/jquery-3.1.0.js"></script>
  <script src="https://unpkg.com/@reactivex/rxjs@5.0.0-beta.12/dist/global/Rx.js"></script>
</body>
</html>
 
/*** Helper Functions ***/
const showTyping = () =>
  $('.typing').text('User is typing...');
const showIdle = () =>
  $('.typing').text('');
const updateTimer = (x) =>
  $('.timer').text(x);
/*** Program Logic ***/
const inputEvents$ = Rx.Observable
  .fromEvent($('#input'), 'input');
const isIdle$ = inputEvents$
  .debounceTime(1000);
isIdle$.subscribe(showIdle);
const typing$ = inputEvents$
  .do(showTyping);
const clock$ = typing$
  .exhaustMap(() => Rx.Observable.interval(1000).takeUntil(isIdle$))
  .scan((acc) => acc + 1, 0)
  .subscribe(updateTimer);
Output 300px

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

Dismiss x
public
Bin info
Doruspro
0viewers