-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c51a59
commit 05bd59f
Showing
2 changed files
with
21 additions
and
14 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
|
||
<body> | ||
|
||
<button id="downBtn">Download</button> | ||
</body> | ||
|
||
</html> |
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
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"); | ||
}, | ||
}); | ||
}); |