From 31dc29ab37b32564a12e47b4ce23aa363cea15dd Mon Sep 17 00:00:00 2001 From: Ewan Date: Thu, 17 Oct 2024 15:38:54 +1100 Subject: [PATCH] return unobserve functions from observe and observeDeep methods --- src/types/AbstractType.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/types/AbstractType.js b/src/types/AbstractType.js index 24fa8802..cac4653f 100644 --- a/src/types/AbstractType.js +++ b/src/types/AbstractType.js @@ -364,20 +364,26 @@ export class AbstractType { /** * Observe all events that are created on this type. + * Returns a function to stop sending events to the provided callback once called * * @param {function(EventType, Transaction):void} f Observer function + * @returns {function():void} */ observe (f) { addEventHandlerListener(this._eH, f) + return () => this.unobserve(f) } /** * Observe all events that are created by this type and its children. + * Returns a function to stop sending events to the provided callback once called * * @param {function(Array>,Transaction):void} f Observer function + * @returns {function():void} */ observeDeep (f) { addEventHandlerListener(this._dEH, f) + return () => this.unobserveDeep(f) } /**