Options
All
  • Public
  • Public/Protected
  • All
Menu

Component that wraps a function or a class method and invokes it in its render method. The component remembers the this value for the function, which allows it to invoke class methods with the proper this. A function can accept a single argument, which can be passed in the arg property to the Functor component.

Normally, the Functor component wraps the function in a watcher, which allows it to react to triggers. It is possible to disable this functionality either by applying the noWatcher decorator to a class method or by passing false to the watch property.

The primary use of the Functor component is to allow class-based components' methods to render different parts of the component and to update these parts independently. If the class method doesn't accept any parameters, then there is no need to use the Functor component explicitly. Such methods can be passed as JSX content and Mimbl will create the Functor components for them.

Example:

class ToDoList extends mim.Component
{
// array of objects of some externally defined ToDo type
@mim.trigger todos: ToDo[] = [];

render(): any
{
return <main>
{this.todos.map( todo => <mim.Functor func={this.renderTodo} arg={todo} />}
</main>
}

renderToDo(todo: ToDo): any
{
return <div>{todo.description}</div>
}
}

Hierarchy

Index

Constructors

constructor

Properties

Readonly isMounted

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 already unmounted. This property allows the component to handle this situation.

props

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

thisArg

thisArg: any

The "this" argument for calling the function. If it is not provided, the current component is used.

Optional 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

displayName

  • get displayName(): string
  • String representation of the component

    Returns string

Methods

callMe

  • Schedules the given function to be called either before or after components update cycle.

    Parameters

    • func: ScheduledFuncType

      Function to be called

    • beforeUpdate: boolean

      If true, the function is called before the component updates cycle; if false - after the cycle.

    • Optional arg: any

      Argument that will be passed to the function.

    • Optional thisArg: 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.

    • Optional tickType: TickSchedulingType

      Defines whether and how Mimbl tick is scheduled after the function is called

    Returns void

fireEvent

  • fireEvent<K>(eventType: K, detail: {}[K]): boolean
  • Fires an event of the given type. The detail parameter is interpreted differently for built-in and custom events. For built-in events (that is, events whose type derives from Event), this is the event object itself. For custom events, it becomes the value of the detail property of the CustomEvent object.

    Type parameters

    • K: never

      Defines a range of possible values for the eventType parameter. K is a key from the TEvent type.

    Parameters

    • eventType: K

      Event type name, which is a key from the TEvents type

    • detail: {}[K]

      Event data, whose type is defined by the type mapped to the key in the TEvents type.

    Returns boolean

getService

  • Retrieves the value for a service with the given ID registered by a closest ancestor component or the default value if none of the ancestor components registered a service with this ID. This method doesn't establish a subscription and only reflects the current state.

    Type parameters

    • K: "ErrorBoundary"

    Parameters

    • id: K

      Unique service identifier

    • Optional defaultValue: IServiceDefinitions[K]

      Default value to return if no publish service is found.

    • Optional useSelf: boolean

      Flag indicating whether the search for the service should start from the virtual node that calls this method. The default value is false meaning the search starts from the parent virtual node.

    Returns IServiceDefinitions[K]

    Current value of the service or default value if no published service is found.

publishService

  • Registers the given value as a service with the given ID that will be available for consumption by descendant components.

    Type parameters

    • K: "ErrorBoundary"

    Parameters

    • id: K

      Unique service identifier

    • value: IServiceDefinitions[K]

      Current value of the service

    • Optional depth: number

      Number of level to watch for changes. The default value is 1; that is, the subscribers will be notified if the service's value or the values of its properties have changed.

    Returns IPublication<K>

    Publication object, which allows setting a new value of the service or changing values of its properties.

subscribeService

  • Subscribes to a service with the given ID. If the service with the given ID is registered by this or one of the ancestor components, the returned subscription object's value property will reference it; otherwise, the value will be set to the defaultValue (if specified) or will remain undefined. Whenever the value of the service that is registered by this or a closest ancestor component is changed, the subscription's value property will receive the new value.

    If the subscription object's value property is used in a component's rendering code, the component will be re-rendered every time the service value is changed.

    Type parameters

    • K: "ErrorBoundary"

    Parameters

    • id: K

      Unique service identifier

    • Optional defaultValue: IServiceDefinitions[K]

      Optional default value that will be assigned if the service is not published yet.

    • Optional useSelf: boolean

      Flag indicating whether the search for the service should start from the virtual node that calls this method. The default value is false meaning the search starts from the parent virtual node.

    Returns ISubscription<K>

    Subscription object, which provides the value of the service and allowes attaching to the event fired when the value is changed.

updateMe

  • updateMe(): void
  • This method is called by the component to request to be updated.

    Returns void

wrap

  • Type parameters

    • T: Function

    Parameters

    • func: T

      Callback function to be wrapped

    • Optional arg: any

      Optional argument to be passed to the callback in addition to the original callback arguments.

    • Optional thisArg: any

      Optional object to be used as this when calling the callback. If this parameter is not defined, the component instance is used, which allows wrapping regular unbound components' methods. This parameter will be ignored if the the function is already bound or is an arrow function.

    • Optional schedulingType: TickSchedulingType

      Type of scheduling the Mimbl tick after the callback function returns.

    Returns T

    Wrapped callback that will run the original callback in the proper context.