omi/index.d.ts

183 lines
5.3 KiB
TypeScript
Raw Normal View History

2017-04-01 23:39:47 +08:00
// Type definitions for Omi v1.2.2
// Project: https://github.com/AlloyTeam/omi
///////////////////////////////////////////////////////////////////////////////
// Omi module (omi.js)
///////////////////////////////////////////////////////////////////////////////
declare namespace Omi {
/*
* Create an instance of the Omi.Component .
*
* Examples:
* export default Hello extends Omi.Component{}
*/
interface ComponentOption{
server: boolean;
ignoreStoreData: boolean;
preventSelfUpdate: boolean;
selfDataFirst: boolean;
domDiffDisabled: boolean;
scopedSelfCSS: boolean
[propName: string]: any;
}
/*
* It should be noted that the installed will be executed during the instantiation, which is not shown above.
* For example, it'll executed when a component is removed and restored, or when the new component is being added.
*
*/
export class Component {
/*
* The constructor;
* When new a constructor
*/
constructor(data: any, option?: ComponentOption);
/*
* The installation. We can process the data that user pass;
* When instantiate
*/
public install?(): void;
/*
* Complete the installation. It'll trigger after HTML being inserted to the page. Please note that it'll trigger when component being removed and restored
* Instantiation and existence
*/
public installed?(): void;
/*
* Uninstall the component. It'll trigger when remove is executed.
* When destroy
*/
public uninstall?(): void;
/*
* Before update.
* When existence
*/
public beforeUpdate?(): void;
/*
* After update.
* When existence
*/
public afterUpdate? (): void;
public render(): string;
public style?(): string;
public beforeRender?(): string;
public useStore?(store: Store): void;
public updateSelf?(): void;
public update?(): void;
public setData?(data: any, update: boolean): void;
public removeChild?(indexOrChild: number | Component ): void;
public remove?(): void;
public restore?(): void;
}
export function $ (selector: string, context: any): HTMLElement;
export function $$(selector: string, context: any): Array<HTMLElement>;
2017-04-02 00:20:18 +08:00
export const STYLEPREFIX: string;
2017-04-01 23:39:47 +08:00
2017-04-02 00:20:18 +08:00
export const STYLESCOPEDPREFIX: string;
2017-04-01 23:39:47 +08:00
2017-04-02 00:20:18 +08:00
export const _instanceId: number;
2017-04-01 23:39:47 +08:00
2017-04-02 00:20:18 +08:00
export interface componentConstructor {
[name: string]: Component
}
2017-04-01 23:39:47 +08:00
export function create (tagName: string, parent: string, setting: any): void
2017-04-02 00:20:18 +08:00
export function createStore (option: any): Store
2017-04-01 23:39:47 +08:00
2017-04-02 00:20:18 +08:00
export const customTags: Array<string>;
2017-04-01 23:39:47 +08:00
/*
* Method: Omi.extendPlugin( pluginName, handler )
* pluginName is the name of the plugin.
* handler is the processor. The handler can get the dom which marked as the pluginName and the instance of the component.
* With Omi.extendPlugin, we can give the dom some ability, and can also be associated with the component instance.
* The above example is not associated with the instance, let's try it:
*/
2017-04-02 00:20:18 +08:00
interface ExtendPluginHandler {
(dom: HTMLElement, instance: Component): void
}
export interface plugins{
[name: string]: ExtendPluginHandler
}
export function extendPlugin(pluginName: string, handler: ExtendPluginHandler): void
2017-04-01 23:39:47 +08:00
export function get(name: string): void
2017-04-02 00:20:18 +08:00
export function getClassFromString(string: string): Component
2017-04-01 23:39:47 +08:00
export function getInstanceId () : number
2017-04-02 00:20:18 +08:00
export function getParameters(dom: HTMLElement, instance: Component, types: string): void
2017-04-01 23:39:47 +08:00
2017-04-02 00:20:18 +08:00
export interface instances {
[component: string]: Component
}
2017-04-01 23:39:47 +08:00
/*
* We use makeHTML to make the component to a tag which can be used in render method. Of course, Omi.makeHTML('List', List);
* can also be written in the end of List component.
*/
export function makeHTML(name: string, component: typeof Component): void
2017-04-02 00:20:18 +08:00
export interface mapping {
[name: string]: any
}
2017-04-01 23:39:47 +08:00
interface MixIndexArrayItem {
value: any;
[indexName: string]: number
}
2017-04-02 00:20:18 +08:00
export function mixIndex(array: Array<any>, key?: string): Array<MixIndexArrayItem>;
2017-04-01 23:39:47 +08:00
export function mixIndexToArray(array: Array<any>, indexName: string): void;
class Store {
constructor(isReady: boolean);
public ready<T>(readyHandle: Array<T>): void;
2017-04-02 00:20:18 +08:00
public addSelfView?(view: Component): void;
public addView?(view: Component): void;
public beReady?(): void;
public update?(): void;
2017-04-01 23:39:47 +08:00
}
/*
*
*/
interface IncrementOrOption {
increment: boolean,
store: Store,
autoStoreToData: boolean
}
export interface Style{
scoper(css: string, prefix: string): string;
addStyle(cssText: string, id: string): void;
}
export function render(component: Component, renderTo: string, incrementOrOption?: IncrementOrOption)
2017-04-02 00:20:18 +08:00
export const style: Style;
2017-04-01 23:39:47 +08:00
/*
*
*/
export function tag(name: string, ctor: typeof Component): void
}
/*
* export a module omi
*/
declare module "omi" {
export default Omi;
}