Options
All
  • Public
  • Public/Protected
  • All
Menu

External module @corpuscule/utils/lib/defineExtendable

This module provides tools to work with restrictions of the Custom Elements spec.

Usage

import defineExtendable from '@corpuscule/utils/lib/defineExtendable'

Index

Functions

Functions

defineExtendable

  • defineExtendable<N>(klass: any, baseClassMethods: Record<N, Function>, extendedClassMethods: Record<N, Function>, initializers: Array<function>): void
  • A workaround for a Corpuscule-decorated class inheritance. Corpuscule decorators applied to a class override user-defined Custom Elements lifecycle hooks like connectedCallback etc. creating an internal worker method which is necessary for Corpuscule elements to work correctly. However, if the user wants to extend the class, the wrapper is unnecessary and could cause undefined behavior and harm the runtime execution.

    This function is a solution to this problem. It replaces a lifecycle hook with a wrapper that calls two different methods depending on whether the class is extended or not. If the class is not extended, the Corpuscule worker is called; otherwise, the original user-defined method is used.

    Type parameters

    • N: PropertyKey

    Parameters

    • klass: any

      a class declaration which lifecycle hooks should be redefined to be extendable.

    • baseClassMethods: Record<N, Function>

      an object with methods that should be used in case the class is not extended.

    • extendedClassMethods: Record<N, Function>

      an object with methods that should be used in case the class is extended.

    • initializers: Array<function>

      an array of functions to register the function to execute during the class instantiation.

    Returns void

Generated using TypeDoc