Allows to call a wrapper function every time a async function is triggered. This allows advanced setups when you work with state management libraries like mobx. You could, for example wrapp all calls through the proxy in a runInAction() wrap.
The list of all registered event listeners and their matching proxy functions by the target and event name
Contains the list of all intervals that are bound on this block
False if this instance was destroyed
The internal event emitter to handle mutation events
The list of registered mutation observers by their target objects
The component which is used as this context inside the proxy instance
Contains the list of all timeouts that are bound on this block
Internal logic to unbind an event from a listener. This method does not do any validation if the proxy still lives so it can be called in the destroy method
Internal logic to unbind all currently registered events
Binds a given listener to a certain event
The target to bind the listener to. Either a html element, the document or the EventBus class
The name of the event to bind the listener to. If you use "@mutation" a MutationObserver will track any changes of the dom and call the listener on it
The listener which is called when the event is emitted on the given target
Default: 0, the lower the number, the earlier the execution. May be a negative value! Note: This only works for event emitters and the event bus. @todo add html event listener options like passive and capture!
Wrap all callbacks to the outside world with this method so you can be sure there won't be issues even if your component is destroyed before the outside function finishes outsideFunction(proxy.callbackProxy((...args) => console.log(args)));
Removes a given interval on the current block
Clears a given timeout id
Call this method when your component is destroyed. The proxy will then unbind all events, timeouts, intervals and block all promises which could lead to errors or memory leaks
Emits a given event which has the option to pass additional arguments.
The target to trigger the event on. Either a html element, the document or the EventBus class
The name of the event to emit
An object of arguments which then are transferred to e.args in your callback
Emits a given hook to process the given arguments
The target to trigger the event on. Either a EventBus, EventEmitter or storage object
The name of the hook to emit
An object of arguments which then are transferred to e.args in your callbacks
Returns true if this proxy is destroyed, false if not
This helper can be used in a promise chain Promise().then(this.promiseProxy()).then(...) This makes sure that even if the current block is destroyed the chained functions will not be executed and may break stuff.
Registers a handler to run in a specified interval. The interval will automatically be stopped when the block is destroyed
Registers a handler to run in a specified interval. The interval will automatically be stopped when the block is destroyed
Registers a timeout to run after a specified timespan. The timout will automatically be stopped when the block is destroyed
Registers a timeout to run after a specified timespan. The timout will automatically be stopped when the block is destroyed
Removes a given listener from a certain event
The target to unbind the listener from. Either a html element, the document or the EventBus class
The event to unbind or @mutation if a mutation observer is used
The listener which should be unbound for the given event
Unbinds all event listeners and mutation objservers from the dom
Generated using TypeDoc
Imagine the following: Your component needs outside connections, either to listen for DOM events, other libraries, hooks into a promise chain, registers a callback, you get the gist. But what if your component gets destroyed? You have to unbind all event listeners, decouple all callbacks, cancel all timeouts and intervals. Have you ever tried to "un-register" a then() in a promise chain? Did you ever forget one a single listener that lead to a memory leak?
Not anymore, I tell you! Behold the sparkling new ComponentProxy-2000 and enter the world of proxying everything your component does with the outside world.
It's so simple: 1. Create a proxy instance inside your component. 2. supply it the component's instance, so the proxy knows it's "this". 3. start registering events, timeouts and intervals by proxy!
When your component reaches the end of its lifecycle call the proxy.destroy() method and the proxy will do all the unbinding for you, cleaning up all the junk with one simple call.