Skip to content

Commit

Permalink
[fixed] adding a dependency to both a signal and a store bug
Browse files Browse the repository at this point in the history
  • Loading branch information
michTheBrandofficial committed Dec 23, 2023
1 parent a4a9afd commit 038cbd9
Show file tree
Hide file tree
Showing 7 changed files with 33,369 additions and 55 deletions.
19 changes: 11 additions & 8 deletions dom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ export const nixixStore = window.$$__NixixStore as GlobalStore;
const Nixix = {
create: function (
tagNameFC: target,
props: Proptype,
...children: ChildrenType
props: () => Proptype,
children: () => ChildrenType
): Element | Array<Element | string | Signal> | undefined {
!nixixStore.jsx &&
((nixixStore.jsx = true), callEffect(() => (nixixStore.jsx = false)));
nixixStore.jsx = true;
let returnedElement: any = null;
if (typeof tagNameFC === "string") {
if (tagNameFC === "fragment") {
Expand All @@ -61,11 +60,12 @@ const Nixix = {
const element = !SVG_ELEMENTTAGS.includes(tagNameFC)
? document.createElement(tagNameFC)
: document.createElementNS(SVG_NAMESPACE, tagNameFC);
setProps(props, element);
setChildren(children, element);
setProps(props?.(), element);
setChildren(children?.(), element);
returnedElement = element;
}
} else returnedElement = buildComponent(tagNameFC, props, children);
} else returnedElement = buildComponent(tagNameFC, props?.(), children?.());
nixixStore.jsx = false
return returnedElement;
},
handleDirectives: handleDirectives_,
Expand Down Expand Up @@ -228,6 +228,7 @@ function buildComponent(
) {
let returnedElement: any = null;
if (isFunction(tagNameFC)) {
nixixStore.jsx = false
const artificialProps = props || {};
Boolean(children?.length) && (artificialProps.children = children);
returnedElement = (tagNameFC as Function)(artificialProps);
Expand Down Expand Up @@ -269,5 +270,7 @@ function turnOnJsx() {
nixixStore.jsx = true;
}

const create = Nixix.create;

export default Nixix;
export { render, setAttribute, turnOnJsx, removeNode };
export { create, render, setAttribute, turnOnJsx, removeNode };
85 changes: 46 additions & 39 deletions dom/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,19 @@
import { LiveFragment } from '../../live-fragment/types';
import { NixixNode } from '../../types/index'
/**
* jsxFactory - Nixix.create()
*/
declare const Nixix: {
create: <T extends keyof JSX.IntrinsicElements>(
target: T | ((props: {}) => JSX.Element) | 'fragment',
props: JSX.IntrinsicElements[T] | null,
...children: (string | Node)[]
) => Element;
};

type RenderConfig = {
commentForLF: boolean
}
/**
* render function
* @param element JSX.Element to render
* @param root element which element will be appended to
*/
export function render(element: NixixNode | (() => NixixNode), root: HTMLElement, {
commentForLF
}?: RenderConfig): void;

/**
* This function should be used to remove nodes, it also removes reactions and signals from the nodes, thereby helping in garbage collection of dom nodes.
*/
export function removeNode(node: Element | Text): boolean;
import { LiveFragment } from "../../live-fragment/types";
import Nixix from "../../types/index";

type RouteType = {
element?: any;
path?: `/${string}`
}
path?: `/${string}`;
};

interface $$__NixixStore {
$$__lastReactionProvider?: 'signal' | 'store';
$$__lastReactionProvider?: "signal" | "store";
commentForLF: boolean;
$$__routeStore?: {
errorRoute?: RouteType;
provider?: LiveFragment;
routeMatch?: {
route: RouteType
route: RouteType;
};
redirect?: string | null;
currentRoute?: RouteType;
Expand All @@ -60,11 +33,45 @@ interface $$__NixixStore {
jsx?: boolean;
}

export const nixixStore: $$__NixixStore;
declare module '../../types/index.d.ts' {
const nixixStore: $$__NixixStore;
/**
* @deprecated PLEASE DO NOT USE THIS FUNCTION
*/
function getStoreValue(store: any): any;

/**
* @deprecated PLEASE DO NOT USE THIS FUNCTION
*/
export function getStoreValue(store: any): any;
type Tagname = | keyof HTMLElementTagNameMap
| keyof SVGElementTagNameMap
| JSXElementConstructor<EmptyObject>
| 'fragment';

function create<T extends Tagname>(
tagNameFC: T,
// @ts-ignore
props: () => JSX.IntrinsicElements[T],
children?: () => NixixNode[]
): NixixNode

type RenderConfig = {
commentForLF: boolean;
};

/**
* render function
* @param element JSX.Element to render
* @param root element which element will be appended to
*/
function render(
element: NixixNode | (() => NixixNode),
root: HTMLElement,
{ commentForLF }?: RenderConfig
): void;

/**
* This function should be used to remove nodes, it also removes reactions and signals from the nodes, thereby helping in garbage collection of dom nodes.
*/
function removeNode(node: Element | Text): boolean;
}

export default Nixix;
export as namespace Nixix;
export = Nixix;
Loading

0 comments on commit 038cbd9

Please sign in to comment.