Files
wekan/client/lib/dateNowTicker.js
T
Lauri Ojansivu ebf1ca6143 Share the card date minute ticker
Replace per-date-badge intervals with one reference-counted ticker. Unsubscribing is idempotent, and destroying the final subscriber clears the shared interval so removed views leave no background timer behind.

Thanks to xet7 !
2026-08-29 06:01:38 +03:00

36 lines
740 B
JavaScript

import { Meteor } from 'meteor/meteor';
import { ReactiveVar } from 'meteor/reactive-var';
const TICK_MS = 60000;
const sharedNow = new ReactiveVar(new Date());
let intervalId = null;
let subscriberCount = 0;
function tick() {
sharedNow.set(new Date());
}
export function subscribeDateNowTicker() {
subscriberCount += 1;
if (subscriberCount === 1) {
tick();
intervalId = Meteor.setInterval(tick, TICK_MS);
}
let subscribed = true;
return {
now: sharedNow,
unsubscribe() {
if (!subscribed) return;
subscribed = false;
subscriberCount -= 1;
if (subscriberCount === 0 && intervalId !== null) {
Meteor.clearInterval(intervalId);
intervalId = null;
}
},
};
}