Skip to content

Commit

Permalink
fix(attr): remove attr as helper method
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This will remove the `attr` made available when using
`view` and `mounted`. Instead you can use `el.dataset` and type your
expected incoming data-* attributes with `Component<{}, Attrs>` and
define those in `Attrs`.
  • Loading branch information
sebkolind committed May 28, 2024
1 parent 93b417c commit 14f9be7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
15 changes: 4 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import { getAttribute } from './attributes';
import {
type Children,
type Context,
type Component,
type TentNode,
type Attrs,
} from './types';
import type { Children, Context, Component, TentNode, Attrs } from './types';
import { createTag, tags } from './tags';
import { walker } from './walker';

Expand Down Expand Up @@ -43,22 +36,22 @@ function mount<S extends {} = {}, A extends Attrs = {}>(

const s = Reflect.set(obj, prop, value);

walker(node, view({ state: proxy, el, attr: getAttribute<A>(el) }));
walker(node, view({ state: proxy, el }));

return s;
},
};

const proxy = new Proxy<S>({ ...state }, handler);

node = view({ state: proxy, el, attr: getAttribute<A>(el) });
node = view({ state: proxy, el });
node.$tent = {
attributes: {},
};

el.append(node);

mounted?.({ state: proxy, el, attr: getAttribute<A>(el) });
mounted?.({ state: proxy, el });
}

export {
Expand Down
2 changes: 0 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
type ComponentContext<S, A extends Attrs> = {
state: S;
el: TentNode<A>;
// @deprecated Use `el.dataset` instead
attr: <K extends keyof A>(name: K) => A[K] | undefined;
};

export type Attrs = {} | undefined;
Expand Down

0 comments on commit 14f9be7

Please sign in to comment.