-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(observables):
stopPropagation
add operator
- Loading branch information
Showing
3 changed files
with
40 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {MonoTypeOperatorFunction} from 'rxjs'; | ||
import {tap} from 'rxjs/operators'; | ||
|
||
export function stopPropagation<T extends Event>(): MonoTypeOperatorFunction<T> { | ||
return tap(e => { | ||
e.stopPropagation(); | ||
}); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {fakeAsync} from '@angular/core/testing'; | ||
import {Subject} from 'rxjs'; | ||
import {first} from 'rxjs/operators'; | ||
import {preventDefault} from '../prevent-default'; | ||
|
||
describe('preventDefault operator function', () => { | ||
it('prevents event default behavior', fakeAsync(() => { | ||
const event = new Event('click'); | ||
const subject = new Subject<Event>(); | ||
|
||
subject.pipe(preventDefault(), first()).subscribe(); | ||
subject.next(event); | ||
|
||
expect(event.defaultPrevented).toBe(true); | ||
})); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {fakeAsync} from '@angular/core/testing'; | ||
import {Subject} from 'rxjs'; | ||
import {first} from 'rxjs/operators'; | ||
import {stopPropagation} from '../stop-propagation'; | ||
|
||
describe('stopPropagation operator function', () => { | ||
it('stops event propagation', fakeAsync(() => { | ||
const event = new Event('click'); | ||
const subject = new Subject<Event>(); | ||
|
||
subject.pipe(stopPropagation(), first()).subscribe(); | ||
subject.next(event); | ||
|
||
expect(event.cancelBubble).toBe(true); | ||
})); | ||
}); |