Skip to content

Commit

Permalink
🐛 Fix interval
Browse files Browse the repository at this point in the history
  • Loading branch information
marcreichel committed Apr 5, 2024
1 parent 54a1dda commit 3b38a26
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
45 changes: 42 additions & 3 deletions dist/alpine-timeago.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/alpine-timeago.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/alpine-timeago.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/alpine-timeago.min.js.map

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import formatDistanceToNow from "date-fns/formatDistanceToNow";
import formatDistanceToNowStrict from "date-fns/formatDistanceToNowStrict";
import parseISO from "date-fns/parseISO";
import isPast from "date-fns/isPast";

let locale = null;

Expand Down Expand Up @@ -50,14 +51,19 @@ function TimeAgo(Alpine) {
locale,
});
}
el.dispatchEvent(new Event("timeago:update", { bubbles: false }));

dispatch(date);
} catch (e) {
console.error(e);
}
};

let interval;

const dispatch = (date) => {
el.dispatchEvent(new CustomEvent("timeago:render", { detail: { isPast: isPast(date) }, bubbles: false }));
};

const setupInterval = (date) => {
let intervalDuration = 30000;
if (modifiers.includes("seconds")) {
Expand Down Expand Up @@ -96,6 +102,8 @@ function TimeAgo(Alpine) {
}

render(date);

setupInterval(date);
});
});

Expand Down

0 comments on commit 3b38a26

Please sign in to comment.