-
-
Save kuncevic/2fcbe20276f37b952842ca8ff15159ea to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { Input } from '@angular/core'; | |
import { BehaviorSubject } from 'rxjs/BehaviorSubject'; | |
export function InputObservable<T>(inputName?: string) { | |
return (target: object, name: string): void => { | |
const subject = new BehaviorSubject(this[name]); | |
if (delete target[name]) { | |
Object.defineProperty(target, name, { | |
set(value: T): void { | |
subject.next(value); | |
}, | |
get(): BehaviorSubject<T> { | |
return subject; | |
}, | |
}); | |
} | |
Input(inputName)(target, name); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment