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>
  <script src="https://unpkg.com/rxjs@5.1.1/bundles/Rx.min.js"></script>
</head>
<body>
</body>
</html>
 
const Observable = Rx.Observable;
var counter = 1;
var updateRequest = Observable.defer(() => mockDataFetch())
    .publishReplay(1, 1000)
    .refCount();
function mockDataFetch() {
    return Observable.of(counter++)
        .delay(100);
}
function mockHttpCache() {
    return updateRequest
        .take(1);
}
mockHttpCache().subscribe(val => console.log("Response 0:", val));
setTimeout(() => mockHttpCache().toPromise()
    .then(val => console.log("Response 50:", val))
, 50);
setTimeout(() => mockHttpCache().toPromise()
    .then(val => console.log("Response 200:", val))
, 200);
setTimeout(() => mockHttpCache().toPromise()
    .then(val => console.log("Response 1200:", val))
, 1200);
setTimeout(() => mockHttpCache().toPromise()
    .then(val => console.log("Response 1500:", val))
, 1500);
setTimeout(() => mockHttpCache().toPromise()
    .then(val => console.log("Response 3500:", val))
, 3500);
Output 300px

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

Dismiss x
public
Bin info
martinsikpro
0viewers