Skip to content

Commit

Permalink
fix: small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBLT committed Mar 17, 2024
1 parent 0ec2dbb commit 2153f57
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
23 changes: 19 additions & 4 deletions packages/@hec.js/ui/lib/src/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const attributeObserver = new MutationObserver((mutations) => {
* @typedef { (name: string, props: T, fn: ComponentConstructor<T>) => void } UIElement
*/

/** @type { UIElement<T> } */
/** @type { UIElement<any> } */
function UIElement(name, props, fn) {

components.set(name, async (
Expand Down Expand Up @@ -121,11 +121,26 @@ function UIElement(name, props, fn) {
emit('::component/' + name);
}

/** @type { UIElement<T> } */
/**
* @template T
* @param { string } name
* @param { T } props
* @param { ComponentConstructor<T> } fn
*/
export const component = (name, props, fn) => UIElement(`component/${ name }`, props, fn);

/** @type { UIElement<T> } */
/**
* @template T
* @param { string } name
* @param { T } props
* @param { ComponentConstructor<T> } fn
*/
export const view = (name, props, fn) => UIElement(`view/${ name }`, props, fn);

/** @type { UIElement<T> } */
/**
* @template T
* @param { string } name
* @param { T } props
* @param { ComponentConstructor<T> } fn
*/
export const page = (name, props, fn) => UIElement(`page/${ name }`, props, fn);
2 changes: 1 addition & 1 deletion packages/@hec.js/ui/lib/src/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const intersectionObserver = new IntersectionObserver((entries) => {
}
}
}, {
rootMargin: '256px',
rootMargin: '512px',
});

new MutationObserver((mutations) => {
Expand Down
6 changes: 5 additions & 1 deletion packages/@hec.js/ui/lib/src/signal.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ export function signal(value = null, options = {}) {
value = v;

if (storage) {
storage.setItem(options.id, JSON.stringify(value));
if (v === null || v === undefined) {
storage.removeItem(options.id);
} else {
storage.setItem(options.id, JSON.stringify(value));
}
}

for (const subscriber of subscribers) {
Expand Down

0 comments on commit 2153f57

Please sign in to comment.