Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Component<E>

Super class of all the components, create automacially when element appearance in the document.

Type parameters

  • E = any

    Event interface in {eventName: (...args) => void} format.

Hierarchy

  • InternalEventEmitter<E & ComponentEvents>
    • Component

Index

Constructors

constructor

  • new Component<E>(el: HTMLElement): Component<E>

Properties

Readonly __restNodeRange

__restNodeRange: NodeRange

To mark the node range of current nodes when created, use for <slot />.

Readonly el

el: HTMLElement

The root element of component.

Readonly refs

refs: Record<string, Element> = ...

Caches referenced elements from :ref="refName". You should redefine the type as {name: HTMLElement, ...}.

Readonly slots

slots: Record<string, Element[]> = ...

Caches slot elements from :slot="slotName". You should redefine the type as {name: HTMLElement[], ...}.

Static style

style: null | string | TemplateResult | (() => string | TemplateResult) = null

This static property contains style text used as styles for current component. Class names will be scoped as .className__componentName. Tag selector will be nested as: p -> com-name p.

You can nest css codes just like in SCSS, and use $ to reference parent selector.

Methods

__emitConnected

  • __emitConnected(isFirstTimeConnected: boolean): void
  • Called after connected each time, also after __emitCreated.

    Parameters

    • isFirstTimeConnected: boolean

    Returns void

__emitCreated

  • __emitCreated(): void

__emitDisconnected

  • __emitDisconnected(): void

__getWatcherGroup

  • __getWatcherGroup(): WatcherGroup

__updateImmediately

  • __updateImmediately(force?: boolean): void
  • Called from a global queued stack to do updating. Set force to true to force updating happens even in a document fragment.

    Parameters

    • force: boolean = false

    Returns void

__updateWatcherGroup

  • __updateWatcherGroup(): void

emit

  • emit<K>(name: K, ...args: any[]): void
  • Emit specified event with event name and parameters.

    Type parameters

    • K: string | number | symbol

    Parameters

    • name: K

      The event name.

    • Rest ...args: any[]

      The parameters that will be passed to event listeners.

    Returns void

hasListener

  • hasListener(name: string, listener: Function, scope?: object): boolean
  • Check whether listener is in the list for listening specified event name.

    Parameters

    • name: string

      The event name.

    • listener: Function

      The event listener to check.

    • Optional scope: object

      The scope binded to listener. If provided, will additionally check whether the scope match.

    Returns boolean

hasListeners

  • hasListeners(name: string): boolean
  • Check whether any listener is listening specified event name.

    Parameters

    • name: string

      The event name.

    Returns boolean

off

  • off<K>(name: K, listener: EventHandler, scope?: object): void
  • Removes the listener that is listening specified event name.

    Type parameters

    • K: string | number | symbol

    Parameters

    • name: K

      The event name.

    • listener: EventHandler

      The event listener, only matched listener will be removed.

    • Optional scope: object

      The scope binded to listener. If provided, remove listener only when scope match.

    Returns void

on

  • on<K>(name: K, listener: EventHandler, scope?: object): void
  • Registers an event listener to listen event with specified name.

    Type parameters

    • K: string | number | symbol

    Parameters

    • name: K

      The event name.

    • listener: EventHandler

      The event listener.

    • Optional scope: object

      The scope will be binded to listener.

    Returns void

once

  • once<K>(name: K, listener: EventHandler, scope?: object): void
  • Registers an event listener to listen event with specified name, triggers for only once.

    Type parameters

    • K: string | number | symbol

    Parameters

    • name: K

      The event name.

    • listener: EventHandler

      The event listener.

    • Optional scope: object

      The scope will be binded to listener.

    Returns void

removeAllListeners

  • removeAllListeners(): void
  • Removes all the event listeners.

    Returns void

scopeClassName

  • scopeClassName(className: string): string
  • returns scoped class name E .name -> .name__com-name

    Parameters

    • className: string

    Returns string

update

  • update(): void
  • Call this to partially or fully update inner contents asynchronously. Never overwrite this method until you know what you are doing.

    Returns void

watch

  • watch<T>(fn: () => T, callback: (value: T) => void): () => void
  • Watchs returned value of fn and calls callback with this value as parameter after the value changed. Will set callback scope as current component.

    Type parameters

    • T

    Parameters

    • fn: () => T
        • (): T
        • Returns T

    • callback: (value: T) => void
        • (value: T): void
        • Parameters

          • value: T

          Returns void

    Returns () => void

      • (): void
      • Returns void

watchImmediately

  • watchImmediately<T>(fn: () => T, callback: (value: T) => void): () => void
  • Watchs returned value of fn and calls callback with this value as parameter after the value changed. Will call callback immediately. Will set callback scope as current component.

    Type parameters

    • T

    Parameters

    • fn: () => T
        • (): T
        • Returns T

    • callback: (value: T) => void
        • (value: T): void
        • Parameters

          • value: T

          Returns void

    Returns () => void

      • (): void
      • Returns void

watchOnce

  • watchOnce<T>(fn: () => T, callback: (value: T) => void): () => void
  • Watchs returned value of fn and calls callback with this value as parameter after the value changed. Calls callback for only once. Will set callback scope as current component.

    Type parameters

    • T

    Parameters

    • fn: () => T
        • (): T
        • Returns T

    • callback: (value: T) => void
        • (value: T): void
        • Parameters

          • value: T

          Returns void

    Returns () => void

      • (): void
      • Returns void

watchUntil

  • watchUntil<T>(fn: () => T, callback: () => void): () => void
  • Watchs returned value of fn and calls callback with this value as parameter after the value becomes true like. Will set callback scope as current component.

    Type parameters

    • T

    Parameters

    • fn: () => T
        • (): T
        • Returns T

    • callback: () => void
        • (): void
        • Returns void

    Returns () => void

      • (): void
      • Returns void

Generated using TypeDoc