Skip to content

Commit

Permalink
lecture-26-2
Browse files Browse the repository at this point in the history
  • Loading branch information
Cistroncoder committed Jan 15, 2023
1 parent 9c51a59 commit 05bd59f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
1 change: 1 addition & 0 deletions lecture-26/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<body>

<button id="downBtn">Download</button>
</body>

</html>
34 changes: 20 additions & 14 deletions lecture-26/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { EMPTY } from "rxjs";
import { EMPTY, defer, fromEvent } from "rxjs";
import { ajax } from "rxjs/ajax";

EMPTY.subscribe({
// the next method will not be called
next: (v) => {
console.log("Next method ", v);
},
// the error method will not be called
error: (err) => {
console.log("Err method ", err);
},
// only the complete method will be called
complete: () => {
console.log("Completed");
},
let isDownloaded = false;

const download$ = defer(() => {
return isDownloaded ? EMPTY : ajax.get("https://httpbin.org/image/png");
});

const downBtn = document.getElementById("downBtn") as HTMLButtonElement;

fromEvent(downBtn, "click").subscribe(() => {
download$.subscribe({
next: (v) => {
isDownloaded = true;
console.log("Image data", v);
},
complete: () => {
console.log("Download completed");
},
});
});

0 comments on commit 05bd59f

Please sign in to comment.