Skip to content

Instantly share code, notes, and snippets.

@kuncevic
Forked from amcdnl/input-observable.ts
Created February 20, 2018 10:27
Show Gist options
  • Save kuncevic/2fcbe20276f37b952842ca8ff15159ea to your computer and use it in GitHub Desktop.
Save kuncevic/2fcbe20276f37b952842ca8ff15159ea to your computer and use it in GitHub Desktop.
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