new functional component syntax

This commit is contained in:
CoolElectronics 2024-02-18 14:36:06 -05:00
parent fcc411d842
commit 2dcae6ad11
No known key found for this signature in database
GPG key ID: F63593D168636C50
2 changed files with 20 additions and 9 deletions

25
AliceJS.d.ts vendored
View file

@ -1,5 +1,7 @@
declare namespace JSX { declare namespace JSX {
export type IntrinsicElements = { [index: string]: any }; export type IntrinsicElements = {
[index: string]: any
};
} }
declare function h( declare function h(
@ -26,19 +28,28 @@ declare var styled: { new: typeof css, rule: typeof rule };
type DLCSS = string; type DLCSS = string;
declare var $el: HTMLElement;
interface Element { interface Element {
$: DLComponent<any> $: OuterComponentTypes & { [index: string | symbol]: any }
} }
interface DLElement<T> extends Element { interface DLElement<T> extends Element {
$: T $: T & OuterComponentTypes
} }
declare var $el: HTMLElement; type ComponentElement<T extends (...args: any) => any> = DLElement<ReturnType<T>>;
type DLComponent<T> = { type OuterComponentTypes = {
css: DLCSS,
root: Element, root: Element,
children: Element[], children: Element[],
}
type InnerComponentTypes = {
css: DLCSS,
mount?: () => void, mount?: () => void,
} & T; }
type ComponentTypes = OuterComponentTypes & InnerComponentTypes;
type Component<Public, Private> = ((this: Public & Private & ComponentTypes, _props: Public) => DLElement<Public>);

4
css.js
View file

@ -20,10 +20,10 @@ function scopify_css(uid, css) {
return cssParsed; return cssParsed;
} }
function tagcss(strings, values, isblock) { function tagcss(strings, values, isblock) {
const uid = `dream-${Array(16) const uid = `dl${Array(5)
.fill(0) .fill(0)
.map(() => { .map(() => {
return Math.floor(Math.random() * 16).toString(16); return Math.floor(Math.random() * 36).toString(36);
}) })
.join("")}`; .join("")}`;