Replies: 3 comments
-
It can be done I think but not in an easy way at the moment. How I would try that is wrap the observable function: function myObservable(value) {
const o = observable(value);
const MySet = o._observers; // watch out because underscore prefixes are mangled by Terser
o._observers = MySetAPIIntercepted(MySet);
return o;
} |
Beta Was this translation helpful? Give feedback.
-
I got it working with function observabler<T>(value: T, onObserversChanged: (observers: Set<Function>) => void) {
const o = observable<T>(value);
//@ts-ignore
const observers: Set<Function> = o.__o; // terser got to this ;(
const addFn = observers.add.bind(observers);
const deleteFn = observers.delete.bind(observers);
observers.add = function(f: Function) {
const added = addFn(f);
onObserversChanged(observers);
return added;
}
observers.delete = function(f: Function) {
const success = deleteFn(f);
onObserversChanged(observers);
return success;
}
return o;
} Note the |
Beta Was this translation helpful? Give feedback.
-
This is useful to me as well thanks for sharing that code! I have an element on the page for debugging which shows all active connections between observers and observables, but have been updating it manually by a button click 😅 This should let me auto update it (carefully without an infinite loop) |
Beta Was this translation helpful? Give feedback.
-
Hi, I was wondering if there is a way to be notified when the amount of subscribers on an observable changes. Something like
I implemented some sort of
pipe
equivalent to RxJS and I would like to have this functionality so I can unobserve the chain of observables in the pipe when the last observable isn't observed anymore.Beta Was this translation helpful? Give feedback.
All reactions