chore(core): update core helpers/interfaces

This commit is contained in:
Adam Bradley
2017-05-24 13:40:39 -05:00
parent d4c382239d
commit 296bc0972a
2 changed files with 87 additions and 32 deletions

View File

@ -3,7 +3,7 @@ export function isDef(s: any): boolean { return s !== undefined && s !== null; }
export function isUndef(s: any): boolean { return s === undefined; }
export function isArray(val: any): val is Array<any> { return (!!val) && (val.constructor === Array); }
export function isArray(val: any): val is Array<any> { return Array.isArray(val); }
export function isObject(val: any): val is Object { return typeof val === 'object'; }
@ -19,10 +19,6 @@ export function isStringOrNumber(s: any): s is (string | number) {
return isString(s) || isNumber(s);
}
export function toCamelCase(str: string) {
return str.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
}
export function toDashCase(str: string) {
return str.replace(/([A-Z])/g, (g) => '-' + g[0].toLowerCase());
}

View File

@ -32,8 +32,8 @@ export interface IonicControllerLoaded {
export interface IonicGlobal {
staticDir?: string;
components?: LoadComponents;
loadComponents?: (coreVersion: number, bundleId: string, modulesImporterFn: ModulesImporterFn, cmp0?: ComponentModeData, cmp1?: ComponentModeData, cmp2?: ComponentModeData) => void;
components?: LoadComponentData[];
defineComponents?: (coreVersion: number, bundleId: string, modulesImporterFn: ModulesImporterFn, cmp0?: ComponentModeData, cmp1?: ComponentModeData, cmp2?: ComponentModeData) => void;
eventNameFn?: (eventName: string) => string;
config?: Object;
loadController?: (ctrlName: string, ctrl: any) => any;
@ -198,51 +198,80 @@ export interface DomControllerCallback {
}
export interface LoadComponents {
[tag: string]: any[];
export interface LoadComponentData {
/**
* tag name (ion-badge)
*/
[0]: string;
/**
* map of the modes and bundle ids
*/
[1]: {
[modeCode: string]: string;
};
/**
* props
*/
[2]: any[];
/**
* bundle priority
*/
[3]: LoadPriority;
}
export type LoadPriority = number;
export interface ComponentModeData {
/**
* tag name (ion-badge)
*/
[0]: string;
/**
* props
*/
[1]: any[][];
/**
* methods
*/
[1]: MethodMeta[];
[2]: MethodMeta[];
/**
* states
*/
[2]: StateMeta[];
[3]: StateMeta[];
/**
* listeners
*/
[3]: ComponentListenersData[];
[4]: ComponentListenersData[];
/**
* watchers
*/
[4]: ComponentWatchersData[];
[5]: ComponentWatchersData[];
/**
* shadow
*/
[5]: boolean;
[6]: boolean;
/**
* mode name (ios, md, wp)
* mode code, which is a number that'll
* map to a mode name later (ios, md, wp)
*/
[6]: number;
[7]: number;
/**
* component mode styles
*/
[7]: string;
[8]: string;
}
@ -313,6 +342,8 @@ export interface PropOptions {
export interface PropMeta {
propName?: string;
propType?: any;
attrName?: string;
attrCase?: number;
}
@ -387,21 +418,18 @@ export interface ComponentMeta {
listeners?: ListenMeta[];
watchers?: WatchMeta[];
states?: StateMeta[];
modes: ModeMeta[];
modes?: {[modeCode: string]: ModeMeta};
shadow?: boolean;
namedSlots?: string[];
obsAttrs?: string[];
componentModule?: any;
priority?: 'high'|'low';
priority?: LoadPriority;
}
export interface ModeMeta {
modeName?: string;
bundleId?: string;
styles?: string;
styleUrls?: string[];
styleElm?: HTMLElement;
}
@ -467,8 +495,8 @@ export interface ComponentRegistry {
export interface ProxyElement extends HTMLElement {
connectedCallback: () => void;
attributeChangedCallback: (attrName: string, oldVal: string, newVal: string, namespace: string) => void;
disconnectedCallback: () => void;
attributeChangedCallback?: (attrName: string, oldVal: string, newVal: string, namespace: string) => void;
disconnectedCallback?: () => void;
$queueUpdate: () => void;
$initLoadComponent: () => void;
@ -483,14 +511,11 @@ export interface ProxyElement extends HTMLElement {
}
export type QueueHandlerId = number;
export type Side = 'left' | 'right' | 'start' | 'end';
export interface RendererApi {
(oldVnode: VNode | Element, vnode: VNode, hostContentNodes?: HostContentNodes): VNode;
(oldVnode: VNode | Element, vnode: VNode, hostContentNodes?: HostContentNodes, isSsrHydrated?: boolean): VNode;
}
@ -540,11 +565,13 @@ export interface VNodeData {
export interface PlatformApi {
registerComponents: (components: LoadComponents) => ComponentMeta[];
registerComponents: (components?: LoadComponentData[]) => ComponentMeta[];
defineComponent: (tag: string, constructor: Function) => void;
getComponentMeta: (tag: string) => ComponentMeta;
loadBundle: (bundleId: string, priority: string, cb: Function) => void;
loadBundle: (bundleId: string, priority: LoadPriority, cb: Function) => void;
queue: QueueApi;
css?: {[cmpModeId: string]: string};
isServer?: boolean;
isElement: (node: Node) => node is Element;
isText: (node: Node) => node is Text;
@ -562,12 +589,14 @@ export interface PlatformApi {
$tagName: (elm: Element) => string;
$setTextContent: (node: Node, text: string | null) => void;
$getTextContent: (node: Node) => string | null;
$getAttribute: (elm: Element, attrName: string) => string;
$getAttribute: (elm: any, attrName: string) => string;
$setAttribute: (elm: any, attrName: string, attrValue: any) => void;
$removeAttribute: (elm: any, attrName: string) => void;
$setClass: (elm: any, cssClassName: string, shouldAddCssClassName: boolean) => void;
$attachComponent: (elm: Element, cmpMeta: ComponentMeta, instance: Component) => void;
$tmpDisconnected: boolean;
}
export interface PlatformConfig {
name: string;
isMatch?: {(url: string, userAgent: string): boolean};
@ -577,9 +606,34 @@ export interface PlatformConfig {
export interface ServerInitConfig {
staticDir: string;
sys?: UniversalSys;
config?: Object;
}
export interface HydrateConfig {
req?: any;
url?: string;
referrer?: string;
userAgent?: string;
cookie?: string;
config?: Object;
}
export interface UniversalSys {
fs?: {
readdirSync?(path: string | Buffer): string[];
readFileSync?(filename: string, encoding: string): string;
statSync?(path: string | Buffer): {
isDirectory?(): boolean;
}
};
path?: {
join?: (...paths: string[]) => string;
};
isValidComponent?: (fileName: string) => boolean;
}
export interface Animation {
new(elm?: Node|Node[]|NodeList): Animation;
@ -668,3 +722,8 @@ export interface IdleDeadline {
export interface IdleOptions {
timeout?: number;
}
export interface BundleCallbacks {
[bundleId: string]: Function[];
}