Skip to content

Commit

Permalink
feat: allow nested components (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebkolind authored Oct 22, 2024
1 parent 4d3127d commit a328127
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function mount<S extends {} = {}, A extends Attrs = {}>(
const state = 'state' in component ? component.state : ({} as S);
const el = element as TentNode<A>;

el.$tent = { attributes: {} };
el.$tent = { attributes: {}, isComponent: true };

const handler = {
get(obj: S, key: string) {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type TentNode<A extends Attrs = undefined> = Node &
mounted?: ({ el }: { el: TentNode }) => void;
keep?: boolean;
};
isComponent?: boolean;
};
dataset: A & DOMStringMap;
children: TentNode<A>[];
Expand Down
1 change: 1 addition & 0 deletions src/walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function walker<A extends Attrs>(oldNode: TentNode<A>, newNode: TentNode<A>) {

if (oc.length === 0 && nc.length === 0) return;
if (oldNode.$tent.attributes.keep) return;
if (oldNode.$tent.isComponent) return;

if (oc.length < nc.length) {
for (let i = 0; i < nc.length; i++) {
Expand Down

0 comments on commit a328127

Please # to comment.