Options
All
  • Public
  • Public/Protected
  • All
Menu

Class FuncProxy

The FuncProxy component wraps a function that produces content. Proxies can wrap instance methods of classes that have access to "this" thus allowing a single class to "host" multiple components that can be updated separately. The FuncProxy component is not intended to be created by developers; instead it is only used in its JSX form as the following:

<FuncProxy func={this.renderSomething} key={...} args={...} thisArg={...} />

There is a simpler method of specifying a rendering function in JSX, e.g.:

<div>{this.renderSomething}</div>

The FuncProxy component is needed in the case where one (or more) of the following is true:

  • There is a need to pass arguments to the function
  • The same function is used multiple times and keys must be used to distinguish between the invocations.
  • The value of "this" inside the function is not the component that does the rendering. That is, the function is not a method of this component.

FuncProxy has a public static Update method that can be called to cause the rendering mechanism to invoke the function wrapped by the FuncProxy.

Hierarchy

Implements

Index

Properties

Readonly props

Component properties passed to the constructor. This is normally used only by managed components and is usually undefined for independent coponents.

vn

Remembered virtual node object through which the component can request services. This is undefined in the component's costructor but will be defined before the call to the (optional) willMount method.

Accessors

isMounted

  • get isMounted(): boolean
  • Determines whether the component is currently mounted. If a component has asynchronous functionality (e.g. fetching data from a server), component's code may be executed after it was alrady unmounted. This property allows the component to handle this situation.

    Returns boolean

Methods

Protected callMeAfterUpdate

  • Schedules the given function to be called after all components scheduled to be updated in the Mimbl tick have already been updated.

    Parameters

    • func: ScheduledFuncType

      Function to be called

    • Optional funcThisArg: any

      Object that will be used as "this" value when the function is called. If this parameter is undefined, the component instance will be used (which allows scheduling regular unbound components' methods). This parameter will be ignored if the the function is already bound or is an arrow function.

    Returns void

Protected callMeBeforeUpdate

  • Schedules the given function to be called before any components scheduled to be updated in the Mimbl tick are updated.

    Parameters

    • func: ScheduledFuncType

      Function to be called

    • Optional funcThisArg: any

      Object that will be used as "this" value when the function is called. If this parameter is undefined, the component instance will be used (which allows scheduling regular unbound components' methods). This parameter will be ignored if the function is already bound or is an arrow function.

    Returns void

render

  • render(): any
  • The render method of the FuncProxy component is never actually called

    Returns any

Protected updateMe

  • This method is called by the component to request to be updated. If no arguments are provided, the entire component is requested to be updated. If arguments are provided, they indicate what rendering functions should be updated.

    Parameters

    • Optional func: RenderMethodType

      Optional rendering function to invoke

    • Optional funcThisArg: any

      Optional value to use as "this" when invoking the rendering function. If undefined, the component's "this" will be used.

    • Optional key: any

      Optional key which distinguishes between multiple uses of the same function. This can be either the "arg" or the "key" property originally passed to the FunProxy component.

    Returns void

Protected wrapCallback

  • Creates a wrapper function with the same signature as the given callback so that if the original callback throws an exception, it is processed by the Mimbl error handling mechanism so that the exception bubbles from this component up the hierarchy until a component that knows to handle errors is found.

    Use this method before passing callbacks to document and window event handlers as well as non-DOM objects that use callbacks, e.g. fetch, Promise, setTimeout, etc. For example:

        class ResizeMonitor extends mim.Component
        {
            private onWindowResize(e: Event): void {};
    
            wrapper: (e: Event): void;
    
            public startResizeMonitoring()
            {
                this.wrapper = this.wrapCallback( this.onWindowResize);
                window.addEventListener( "resize", this.wrapper);
            }
    
            public stopResizeMonitoring()
            {
                window.removeEventListener( "resize", this.wrapper);
                this.wrapper = undefined;
            }
        }

    Type parameters

    • T: Function

    Parameters

    • func: T

      Method/function to be wrapped

    • Optional funcThisArg: any

      Optional value of "this" to bind the callback to. If this parameter is undefined, the component instance will be used. This parameter will be ignored if the the function is already bound or is an arrow function.

    • Optional schedulingType: TickSchedulingType

      Type determining whether and how a Mimbl tick should be scheduled after callback invocation.

    Returns T

    Function that has the same signature as the given callback and that should be used instead of the original callback

Generated using TypeDoc