Created
November 9, 2018 13:46
-
-
Save WouterSpaak/2fb26c5b5f9e21c5c387a250f2a3b4bf to your computer and use it in GitHub Desktop.
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
// Creating an internal subject that will recieve values from | |
// Angular calling the shadowed method with new values. | |
const subject = new Subject<any>(); | |
// We need a super secret string to monkey patch a new method onto | |
// the target class. | |
const newKey = `__keyForObservableHostListener__${key}`; | |
Object.defineProperties(target, { | |
[newKey]: { | |
// here, we just next() the recieved values into the internal subject. | |
value: (val: any) => subject.next(val), | |
configurable: false, | |
enumerable: false, | |
writable: false | |
}, | |
// And here, we're assigning our internal to the original key. | |
[key]: { | |
get() { | |
if (operator) { | |
return subject.pipe(operator); | |
} else { | |
return subject.asObservable(); | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment