Created
December 31, 2019 22:28
-
-
Save TheMcMurder/b01820b17f3b8dc0ae035c5cbedfcdba to your computer and use it in GitHub Desktop.
Working SystemJS and rxjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=device-width" /> | |
<title></title> | |
<script src='https://cdn.jsdelivr.net/npm/[email protected]/dist/system.js'></script> | |
<script src='https://cdn.jsdelivr.net/npm/[email protected]/dist/extras/amd.js'></script> | |
<script src='https://cdn.jsdelivr.net/npm/[email protected]/dist/extras/named-exports.js'></script> | |
<script src='https://cdn.jsdelivr.net/npm/[email protected]/dist/extras/named-register.js'></script> | |
<script src='https://cdn.jsdelivr.net/npm/[email protected]/dist/extras/use-default.js'></script> | |
</head> | |
<body> | |
<script type="systemjs-importmap"> | |
{"imports":{"rxjs":"https://cdn.jsdelivr.net/npm/@reactivex/[email protected]/dist/global/rxjs.umd.js"}} | |
</script> | |
<script> | |
// rxjs hack | |
const originalResolve = System.resolve | |
System.resolve = function (name) { | |
if (name === 'rxjs/operators') { | |
return 'rxjs-operators.js' | |
} else { | |
return originalResolve.apply(this, arguments) | |
} | |
} | |
System.register('rxjs-operators.js', [], _export => { | |
System.import('rxjs').then(rxjs => { | |
_export(rxjs.operators) | |
}) | |
return {} | |
}) | |
</script> | |
<div> | |
<button onClick='workingStream()'>Trigger observable stream</button> | |
</div> | |
</body> | |
<script> | |
function workingStream() { | |
Promise.all([ | |
System.import('rxjs'), | |
System.import('rxjs/operators') | |
]).then(([rxjs, operators]) => { | |
const sub = rxjs.interval(1000).pipe( | |
operators.tap((v) => console.log('v', v)), | |
operators.finalize(() => { | |
console.log('************************') | |
console.log('finalize called') | |
console.log('************************') | |
}) | |
).subscribe() | |
setTimeout(() => { | |
console.log('trigger unsubscribe on failing stream') | |
sub.unsubscribe() | |
}, 3000) | |
} | |
) | |
} | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment