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>RxJS 5 Operators</title>
  <script src="https://npmcdn.com/@reactivex/rxjs@5.0.0-beta.3/dist/global/Rx.umd.js"></script>
</head>
<body>
</body>
</html>
 
const bSubject = new Rx.BehaviorSubject<number[]>([]);
let numberList: Observable<number[]>;
numberList = bSubject.asObservable()
.scan((acc, val) => {
  return acc.concat(val);
});
numberList.subscribe((val) => {
  console.log(val);
});
let i = 0;
setInterval(() => { 
  console.log('Fetching data... Numberlist is now: ');
  bSubject.next(i);
  i++;
}, 3000);
setTimeout(() => { 
  console.log('Realtime push event occurred!');
  console.log('Adding number to array!');
  
  // This should be prepended to the beginning of the array
  // and produce the desired result [1337, 0, 1]
  const pushNumber = 1337;
  bSubject.next(pushNumber);
},6000);
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers