-
Notifications
You must be signed in to change notification settings - Fork 3
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
3b4d5ac
commit 555165d
Showing
3 changed files
with
46 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
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,38 @@ | ||
/** | ||
* Created by tushar.mathur on 14/10/16. | ||
*/ | ||
|
||
|
||
import {IObservable} from '../types/core/IObservable' | ||
import {IObserver} from '../types/core/IObserver' | ||
import {IScheduler} from '../types/IScheduler' | ||
import {ISubscription} from '../types/core/ISubscription' | ||
import {IListener} from '../types/IListener' | ||
|
||
|
||
export class DOMSubscription implements ISubscription { | ||
closed: boolean = false | ||
|
||
constructor (private element: HTMLElement, private listener: IListener, private name: string) { | ||
} | ||
|
||
unsubscribe (): void { | ||
this.element.removeEventListener(this.name, this.listener) | ||
} | ||
} | ||
|
||
export class DOMObservable implements IObservable<Event> { | ||
constructor (private element: HTMLElement, private name: string) { | ||
} | ||
|
||
subscribe (observer: IObserver<Event>, scheduler: IScheduler): ISubscription { | ||
const listener = (e: Event) => observer.next(e) | ||
this.element.addEventListener(this.name, listener) | ||
return new DOMSubscription(this.element, listener, this.name) | ||
} | ||
|
||
} | ||
|
||
export function fromDOM (element: HTMLElement, name: string) { | ||
return new DOMObservable(element, name) | ||
} |
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,7 @@ | ||
/** | ||
* Created by tushar.mathur on 14/10/16. | ||
*/ | ||
|
||
export interface IListener { | ||
(e: Event): void | ||
} |