Skip to content

Commit

Permalink
add JSX types (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bloomca authored Jun 3, 2024
1 parent e5568d2 commit ae56a5b
Show file tree
Hide file tree
Showing 4 changed files with 3,262 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/hooks/create-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ import type {
VelesElement,
VelesComponent,
VelesStringElement,
AttributeHelper,
} from "../types";

type AttributeHelper = {
(htmlElement: HTMLElement, attributeName: string, node: VelesElement): string;
velesAttribute: boolean;
};

export type State<ValueType> = {
trackValue(
cb: (value: ValueType) => void | Function,
Expand Down Expand Up @@ -51,7 +47,7 @@ export type State<ValueType> = {
value2: SelectorValueType
) => boolean
): VelesElement | VelesComponent | VelesStringElement;
useAttribute(cb?: (value: ValueType) => string): AttributeHelper;
useAttribute(cb?: (value: ValueType) => any): AttributeHelper<any>;
useValueIterator<Element>(
options: {
key: string | ((options: { element: Element; index: number }) => string);
Expand Down Expand Up @@ -296,8 +292,8 @@ function createState<T>(
// 4. provide a way to listen to position value.
// It should be a separate subscription.
},
useAttribute: (cb?: (value: T) => string) => {
const attributeValue = cb ? cb(value) : String(value);
useAttribute: (cb?: (value: T) => any) => {
const attributeValue = cb ? cb(value) : value;

const attributeHelper = (
htmlElement: HTMLElement,
Expand Down Expand Up @@ -420,7 +416,7 @@ function createState<T>(
// attributes
// the HTML node does not change, so we don't need to modify the array
trackingAttributes.forEach(({ cb, htmlElement, attributeName }) => {
const newAttributeValue = cb ? cb(value) : String(value);
const newAttributeValue = cb ? cb(value) : value;

htmlElement.setAttribute(attributeName, newAttributeValue);
});
Expand Down
2 changes: 2 additions & 0 deletions src/jsx-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ export {
createElement as jsxDEV,
} from "./create-element";
export { Fragment } from "./fragment";

export type { JSX } from "./jsx";
Loading

0 comments on commit ae56a5b

Please sign in to comment.