mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
refactor(all): data -> componentProps
This commit is contained in:
@@ -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
19
core/src/utils/lazy.ts
Normal 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();
|
||||
});
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user