Options
All
  • Public
  • Public/Protected
  • All
Menu

Project @pucelle/flit

Index

Type aliases

Context

Context: Component | null

Context is the scope when compiling a template. When uses render or renderComponent, you can choose to pass a context parameter, So the .property and @click=${eventHandler} can capture right context. Context may be null, in this senoario template should context-free.

Functions

addGlobalStyle

  • addGlobalStyle(style: ComponentStyle): HTMLStyleElement
  • Add a global style codes.

    Parameters

    • style: ComponentStyle

    Returns HTMLStyleElement

Const cache

  • cache(changableContent, ?options) will toggle rendering content, and also cache old content to restore it quickly. Note that when old rendering result restored, the scroll positions in it will fall back to start position.

    Parameters

    Returns DirectiveResult

clearTransition

  • clearTransition(el: Element): void
  • Clear the transition that is running in the element.

    Parameters

    • el: Element

    Returns void

css

  • css(strings: TemplateStringsArray, ...values: any[]): TemplateResult

define

  • define(name: string): (Com: ComponentConstructor) => void
  • define(name: string, Com: ComponentConstructor): void
  • Returns a decorator to defined followed class as a component.

    Parameters

    • name: string

      The component name.

    Returns (Com: ComponentConstructor) => void

      • (Com: ComponentConstructor): void
      • Parameters

        • Com: ComponentConstructor

        Returns void

  • Defines a component with specified name. Defines a custom element, but just used to start the defined component

    Parameters

    • name: string

      The component name.

    • Com: ComponentConstructor

      The Component class constructor.

    Returns void

defineBinding

  • defineBinding(name: string): (Binding: BindingConstructor) => void
  • defineBinding<A>(name: string, Binding: BindingConstructor): () => BindingResult<A>
  • Returns a define decorator to defined followed class as a binding class with specified name.

    Parameters

    • name: string

      The binding name.

    Returns (Binding: BindingConstructor) => void

      • (Binding: BindingConstructor): void
      • Parameters

        • Binding: BindingConstructor

        Returns void

  • Define a binding class which with bind with an element and modify it's attributes or properties. Returns a function call which will generate a BingingResult.

    Type parameters

    • A: any[]

    Parameters

    • name: string

      The binding name.

    • Binding: BindingConstructor

    Returns () => BindingResult<A>

defineDirective

  • defineDirective(Dir: DirectiveConstructor): (...args: any[]) => DirectiveResult
  • Defines a directive from a class which implements Directive. Returns a function call which will generate a DirectiveResult.

    A Directive works like Binding, but it used to generate HTML code pieces, not like Binding to modify properties of an element.

    Parameters

    • Dir: DirectiveConstructor

    Returns (...args: any[]) => DirectiveResult

defineTransion

  • defineTransion(name: string, TransitionConstructor: JSTransitionConstructor): void
  • Define a JS transiton and process all transition details internally.

    Parameters

    • name: string
    • TransitionConstructor: JSTransitionConstructor

    Returns void

getCSSEasingValue

  • getCSSEasingValue(easing: TransitionEasing): string
  • Get cubic-bezier(...) as CSS easing from easing name.

    Parameters

    • easing: TransitionEasing

      The extended easing name.

    Returns string

getClosestComponentOfType

  • getClosestComponentOfType<C>(el: Element, Com: C): InstanceType<C> | null
  • Get closest component matches constructor from the closest ancestor custom element. It's very common that you extend a component and define a new custom element, So you will can't find the parent component from the tag name. But you can still match super class by this method.

    Type parameters

    • C: ComponentConstructor

    Parameters

    • el: Element

      The element to search from it and it's ancestors for component instance.

    • Com: C

      The component constructor to search.

    Returns InstanceType<C> | null

getComponent

  • getComponent(el: HTMLElement): Component | null

getComponentAsync

  • getComponentAsync(el: HTMLElement): Promise<Component | null>
  • Get component instance from root element asynchronously. Returns a promise which will be resolved after component created and triggers created event.

    Parameters

    • el: HTMLElement

      The element to get component instance at.

    Returns Promise<Component | null>

getRenderedAsComponent

  • Get a component immediately from a just rendered templated.

    Parameters

    • template: Template

      The just rendered template from render or renderUpdatable.

    Returns Component | null

Const hide

  • hide() binding will update element's visibility state.

    hide(hidden: any, transition: TransitionOptions) hide(hidden: any, options: {transition: TransitionOptions, enterAtStart, leaveAtStart, onend})

    Parameters

    Returns BindingResult<any[]>

html

  • html(strings: TemplateStringsArray, ...values: any[]): TemplateResult

Const liveAsyncRepeat

  • Gerenate live repeat elements, reuse elements as much as possible when data changed. Compare to repeat directive, it will only show partial elements in viewport when you scroll it.

    Type parameters

    • Item

    Parameters

    • options: LiveAsyncRepeatDataOptions<Item>

      Options for live rendering.

    • templateFn: LiveTemplateFn<Item>

      The fucntion which will return a template from one iterable data and index position.

    • Optional liveRepeatOptions: LiveRepeatOptions
    • Optional transitionOptions: ContextualTransitionOptions

      The transition options, it can be a transition name, property or properties, or {transition, enterAtStart}.

    Returns DirectiveResult

Const liveRepeat

  • liveRepeat(items, () => html..., ?liveRepeatOptions, ?transitionOptions) gerenates partial elements only in current viewport, and keeps re-rendering to cover current viewport after you scrolled.

    Note the liveRepeat directive must be contained in the html struct like <div title="as a scroll parent" style="overflow: auto | scroll; position: relative;"> <div title="as a scroll slider" style="position: absolute;"> ${liveRepeat(...)} </div> </div>

    Type parameters

    • Item

    Parameters

    • data: Iterable<Item>
    • templateFn: TemplateFn<Item>

      The fucntion which will return a template result from data item and index position. Rendered nodes must be contained in a container element.

    • Optional liveRepeatOptions: LiveRepeatOptions

      Options for live rendering.

    • Optional transitionOptions: ContextualTransitionOptions

      The transition options, it can be a transition name, property or properties, or {transition, enterAtStart}.

    Returns DirectiveResult

observe

  • observe<T>(value: T): T
  • Begin to track property changes of value, if use value during a updating of a component or watcher, Then the property changes of returned observed object will trigger the component or watcher to be updated.

    Note that it returns a proxy, it can be used just like original object, but it's not absolutly equals with original value, and comparing with === will return false. So it may cause some issues if you cached the original object and compare it with observed one.

    Normally you don't need to call this method, properties of components will be observed automatically. But once an object was observed, it can't be revoked.

    Type parameters

    • T

    Parameters

    • value: T

    Returns T

observeGetting

  • observeGetting<T>(object: T, getterProperty: keyof T): any
  • After consider much about getter, we decided to drop supports for observing getters automatically. The main reason is after we observed getter calls in a proxy, We can't determine this is a getter calls, and we must follow prototype chains to find the descriptor, then we can know it's a getter or normal property. This will slow the whole observing system.

    You can still observe a getter manually according to this method:

    o = {get p(){...}} Uses observeGetting(o, 'p') instead of o.p.

    Type parameters

    • T

    Parameters

    • object: T
    • getterProperty: keyof T

    Returns any

off

  • off(el: EventTarget, name: string, handler: EventHandler, scope?: object): void
  • Unregister an event listener on element.

    Parameters

    • el: EventTarget

      The element to unregister listener on.

    • name: string

      The event name with or without modifiers.

    • handler: EventHandler

      The event handler.

    • Optional scope: object

      The event context used to call handler. If specified, it must be match too.

    Returns void

on

  • on(el: EventTarget, name: string, handler: EventHandler, scope?: object): void
  • Register an event listener on element.

    Parameters

    • el: EventTarget

      The element to register listener on.

    • name: string

      The event name, it can be click:left or keydown:enter.

    • handler: EventHandler

      The event handler.

    • Optional scope: object

      The event context used to call handler. You can remove it easily by specify the same scope.

    Returns void

onRenderComplete

  • onRenderComplete(callback: () => void): void
  • Calls callback after all the components and watchers updated and rendering completed. Note that it was called before renderComplete.

    Parameters

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

    Returns void

once

  • once(el: EventTarget, name: string, handler: EventHandler, scope?: object): void
  • Register an event listener on element, and will be triggered only for once.

    Parameters

    • el: EventTarget

      The element to register listener on.

    • name: string

      The event name, it can be click:left or keydown:enter.

    • handler: EventHandler

      The event handler.

    • Optional scope: object

      The event context used to call handler. You can remove it easily by specify the same scope.

    Returns void

refBinding

  • Reference binding instance after it created and before updating.

    Parameters

    • result: BindingResult
    • ref: (binding: Binding) => void
        • (binding: Binding): void
        • Parameters

          • binding: Binding

          Returns void

    Returns BindingResult<any[]>

refDirective

render

  • Render html codes or a template result like html... within a context. Returns the rendered template, you may append it to another element, or extract to a fragment and insert into any place. Otherwise you can also patch it with another template result.

    Parameters

    Returns Template

renderComplete

  • renderComplete(): Promise<void>
  • Returns a promise which will be resolved after all the components and watchers updated and rendering completed. Note that it was called after onRenderComplete.

    Returns Promise<void>

renderUpdatable

  • Render template result like html... that returned from renderFn. Returns the rendered template, you may append it to another element, or extract to a fragment and insert into any place. Otherwise returns a unwatch function, call which will stop watching renderFn.

    Will watch renderFn, If it's dependent datas changed, will automaticaly updated and call onUpdate.

    Parameters

    Returns { template: Template; unwatch: () => void }

    • template: Template
    • unwatch: () => void
        • (): void
        • Returns void

Const repeat

  • repeat(items, () => html..., ?options) gerenates repeated elements, and will reuse elements as much as possible when data changed. Currently the repeat directive reuses rendered elements by data objects, no key can be specified. If you do need to reuse elements by a key, try repeat the key values.

    Type parameters

    • T

    Parameters

    • items: null | Iterable<T>

      The iterable data, each item in it will pass to templateFn.

    • templateFn: TemplateFn<T>

      The fucntion which will return a template from one iterable data item and index position.

    • Optional options: ContextualTransitionOptions

      The transition options, it can be a transition name, property or properties, or {transition, enterAtStart}.

    Returns DirectiveResult

Const show

  • show(...) binding will update element's visibility state. You may also use :show if no need to specify transition.

    show(visible: any, transition: TransitionOptions) show(visible: any, options: {transition: TransitionOptions, enterAtStart, leaveAtStart, onend})

    Parameters

    Returns BindingResult<any[]>

svg

  • svg(strings: TemplateStringsArray, ...values: any[]): TemplateResult

Const toggle

  • toggle(changableContent, ?options) toggles rendering content and can play enter or leave transition easily.

    Parameters

    Returns DirectiveResult

updateAllComponents

  • updateAllComponents(): void
  • Updates all the components that elements are connected nto document, and their watchers. e.g., you may call this after language changes and not automatically detected.

    Returns void

updateAllGlobalWatchers

  • updateAllGlobalWatchers(): void
  • Updates all the global watchers registered from watch...(). e.g., you may call this after language changes and not automatically detected.

    Returns void

updateAllStyles

  • updateAllStyles(): void
  • Updates all style codes for all the components, you may call this after theme changed.

    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 if the value changed.

    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 if the value changed. Will call callback immediately.

    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 if the value changed. Only calls callback for once.

    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: () => any, callback: (value: T) => void): () => void
  • Watchs returneded values of fn and calls callback if this value becomes true like.

    Type parameters

    • T

    Parameters

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

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

          • value: T

          Returns void

    Returns () => void

      • (): void
      • Returns void

Generated using TypeDoc