ce-decorators
Version:
Custom Element decorators for typescript
126 lines (125 loc) • 4.32 kB
TypeScript
/**
* Copyright (c) 2018 Mathis Zeiher
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
import { COMPONENT_STATE } from './componentstate';
import { PROPERTY_STATE } from './propertystate';
import { TemplateResult } from './lit-html';
/**
* interface for an indexable element
*/
export interface IndexableElement {
[index: string]: any;
}
/**
* define the render strategy for the control
*/
export declare enum RENDER_STRATEGY {
DEFAULT = 0,
LAZY = 1,
PIPELINE_EXPERIMENTAL = 2
}
/**
* Base class for all custom elements
*/
export declare abstract class CustomElement extends HTMLElement {
static _fromAttribute(this: typeof CustomElement, name: string, oldValue: any, newValue: any, instance: CustomElement): void;
static _fromProperty(this: typeof CustomElement, propertyKey: string, oldValue: any, newValue: any, instance: CustomElement): void;
private static _reflectAttributes;
static readonly observedAttributes: Array<string>;
protected _renderStrategy: RENDER_STRATEGY;
protected _renderCallbackResolver: () => void;
protected _componentState: COMPONENT_STATE;
protected _propertyState: PROPERTY_STATE;
protected _renderScheduled: boolean;
protected _templateCache: TemplateStringsArray;
protected _firstRender: boolean;
protected _renderCompletedCallbacks: Array<() => void>;
protected _constructedCompletedCallbacks: Array<() => void>;
protected _layoutRAFReference: number;
constructor();
/**
* should return the DOM to be rendered
*/
abstract render(): TemplateResult;
/**
* is called when the element is attached to the DOM
*/
componentConnected(): void;
/**
* is called when the element is dettached from the DOM
*/
componentDisconnected(): void;
/**
* is called just before render() will be exexuted
*/
componentWillRender(): void;
/**
* is called just after render() will be exexuted
*/
componentDidRender(): void;
/**
* is called just after the first render()
*/
componentFirstRender(): void;
/**
* is called after render and broser layouting
*/
componentDidLayout(): void;
/**
* return element whre the DOM from render will be rendered to
*/
renderToElement(): Element | ShadowRoot;
/**
* return a Promise which will be resolved after
* construction of the element
*
* @returns Promise<void> promise which will resolve after construction is complete
*/
waitForConstruction(): Promise<{}>;
/**
* return a Promise which will be resolved after a
* successfull render
*
* @returns Promise<void>
*/
waitForRender(): Promise<{}>;
/**
* Schedule a new render (the render will only be scheduled) if
* the componentstate is CONNECTED and propertystate is DIRTY
*
* force will force a re-render
*
* @param force force the re-render
*/
scheduleRender(force?: boolean): void;
/**
* build-in function please do not override
*/
connectedCallback(): void;
/**
* build-in function please do not override
*/
disconnectedCallback(): void;
/**
* build-in function please do not override
*/
attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
}
/**
* shorthand for lazy rendered custom element
*/
export declare abstract class LazyCustomElement extends CustomElement {
constructor();
}