Skip to content

Instantly share code, notes, and snippets.

@Bretto
Last active April 5, 2020 11:08
Show Gist options
  • Save Bretto/67d3e2a0504ce06da0608795d90c7fce to your computer and use it in GitHub Desktop.
Save Bretto/67d3e2a0504ce06da0608795d90c7fce to your computer and use it in GitHub Desktop.
takeUntil
const click$ = Rx.Observable
.fromEvent(document, 'click');
const four$ = Rx.Observable.interval(4000).take(1);
/*
click$ --c------c---c-c-----c---c---c-
four$ -----------------0|
clickUntilFour$ --c------c---c-c-|
*/
const clickUntilFour$ = click$.takeUntil(four$);
clickUntilFour$.subscribe(function (ev) {
console.log(ev.clientX) || displayInPreview(ev.clientX);
});
// display in plunker preview
function displayInPreview(string) {
var newDiv = document.createElement("div");
var newContent = document.createTextNode(string);
newDiv.appendChild(newContent);
document.body.appendChild(newDiv)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment