Skip to content

Commit

Permalink
svelteTime action uses $effect
Browse files Browse the repository at this point in the history
  • Loading branch information
metonym committed Jan 23, 2025
1 parent 12f1ce3 commit b40a4bf
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { dayjs } from "./dayjs";
export { svelteTime } from "./svelte-time";
export { svelteTime } from "./svelte-time.svelte";
export { default } from "./Time.svelte";
File renamed without changes.
15 changes: 6 additions & 9 deletions src/svelte-time.js → src/svelte-time.svelte.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { dayjs } from "./dayjs";

/**
* @typedef {import("./svelte-time").SvelteTimeOptions} SvelteTimeOptions
* @typedef {import("./svelte-time.svelte").SvelteTimeOptions} SvelteTimeOptions
* @typedef {import ("svelte/action").Action<HTMLElement, Partial<SvelteTimeOptions>>} SvelteTimeAction
* @type {SvelteTimeAction}
*/
Expand Down Expand Up @@ -45,14 +45,11 @@ export const svelteTime = (node, options = {}) => {
node.innerText = relative ? formatted_from : formatted;
};

setTime(node, options);
$effect(() => {
setTime(node, options);

return {
update(options = {}) {
setTime(node, options);
},
destroy() {
return () => {
clearInterval(interval);
},
};
};
});
};

0 comments on commit b40a4bf

Please sign in to comment.