Skip to content

Instantly share code, notes, and snippets.

@Osmandiyaka
Osmandiyaka / doubleClick.js
Last active April 17, 2020 21:04
Using rxjs to adapt a click event to a double click in angular
Let assume you have a third party angular component, myExtComp and you are using it in your own component like this:
<myExtComp (onItemClicked)="myItemClicked($event)"> </myExtComp>
Notice the third party component exposes only a click event. What if instead of the click event, you would like to
listen for a double click event. Well with rxjs, this is very trivial. Look at how you can adapt an external click
event into a double click event in angular using rxjs
import { Component, OnInit, ViewChild, ViewEncapsulation, ChangeDetectorRef, AfterViewInit, Injector } from '@angular/core';
import { Subject, fromEvent, asyncScheduler } from 'rxjs';
import { debounceTime, map, distinctUntilChanged, filter, buffer, } from 'rxjs/operators';