I am want to run RxJs code snippets in a single HTML file. The below example runs
<!DOCTYPE html>
<!--
Created using JS Bin
http://jsbin.com
Copyright (c) 2022 by anonymous (http://jsbin.com/gemebopifu/1/edit)
Released under the MIT license: http://jsbin.mit-license.org
-->
<meta name="robots" content="noindex" />
<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>
<script id="jsbin-javascript">
//emit value every 1s
const source = Rx.Observable.interval(1000);
//sample last emitted value from source every 2s
const example = source.sample(Rx.Observable.interval(2000));
//output: 2..4..6..8..
const subscribe = example.subscribe((val) => console.log(val));
</script>
</body>
</html>
However, if I replace it with the unpkg CDN (), it does not work
https://unpkg.com/browse/rxjs@7.5.4/dist/bundles/rxjs.umd.js
So clearly I can't replace directly.
For unpkg it should be: https://unpkg.com/rxjs@7.5.5/dist/bundles/rxjs.umd.js
Here's the working solution:
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>RxJS 5 Operators</title>
<script src="https://unpkg.com/rxjs@7.5.5/dist/bundles/rxjs.umd.js"></script>
</head>
<body>
<script id="jsbin-javascript">
//emit value every 1s
const source = window.rxjs.interval(1000);
//sample last emitted value from source every 2s
const example = window.rxjs.interval(2000);
//output: 2..4..6..8..
const subscribe = example.subscribe((val) => console.log(val));
</script>
</body>