refactor(all): data -> componentProps

This commit is contained in:
Manu Mtz.-Almeida
2018-03-29 18:18:02 +02:00
parent ce500858fe
commit a36913e9db
17 changed files with 115 additions and 119 deletions

View File

@@ -1,17 +1,18 @@
import { ComponentRef } from '..';
export interface FrameworkDelegate {
attachViewToDom(container: any, component: any, propsOrDataObj?: any, cssClasses?: string[]): Promise<HTMLElement>;
removeViewFromDom(container: any, component: any): Promise<void>;
}
export function attachComponent(delegate: FrameworkDelegate, container: Element, component: string|HTMLElement, cssClasses?: string[], params?: {[key: string]: any}): Promise<HTMLElement> {
export function attachComponent(delegate: FrameworkDelegate, container: Element, component: ComponentRef, cssClasses?: string[], componentProps?: {[key: string]: any}): Promise<HTMLElement> {
if (delegate) {
return delegate.attachViewToDom(container, component, params, cssClasses);
return delegate.attachViewToDom(container, component, componentProps, cssClasses);
}
const el = (typeof component === 'string') ? document.createElement(component) : component;
cssClasses && cssClasses.forEach(c => el.classList.add(c));
params && Object.assign(el, params);
componentProps && Object.assign(el, componentProps);
container.appendChild(el);
if ((el as any).componentOnReady) {

19
core/src/utils/lazy.ts Normal file
View File

@@ -0,0 +1,19 @@
export function waitUntilVisible(el: HTMLElement, callback?: Function) {
return new Promise((resolve) => {
if ('IntersectionObserver' in window) {
const io = new IntersectionObserver(data => {
if (data[0].isIntersecting) {
resolve();
io.disconnect();
}
});
io.observe(el);
} else {
// fall back to setTimeout for Safari and IE
setTimeout(() => resolve(), 300);
}
}).then(() => {
callback && callback();
});
}

View File

@@ -50,8 +50,11 @@ export function getButtonClassMap(buttonType: string, mode: string): CssClassMap
};
}
export function getClassList(classes: string | undefined): string[] {
export function getClassList(classes: string | string[] | undefined): string[] {
if (classes) {
if (Array.isArray(classes)) {
return classes;
}
return classes
.split(' ')
.filter(c => c.trim() !== '');
@@ -59,7 +62,7 @@ export function getClassList(classes: string | undefined): string[] {
return [];
}
export function getClassMap(classes: string | undefined): CssClassMap {
export function getClassMap(classes: string | string[] | undefined): CssClassMap {
const map: CssClassMap = {};
getClassList(classes).forEach(c => map[c] = true);
return map;