Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only use a single timer/setInterval #96

Closed
Soviut opened this issue Oct 23, 2012 · 5 comments
Closed

Only use a single timer/setInterval #96

Soviut opened this issue Oct 23, 2012 · 5 comments

Comments

@Soviut
Copy link

Soviut commented Oct 23, 2012

It would seem to make sense that a single "global" timer could be used on a page rather than an individual timer per element. The reference to the timer could be stored in the $.data() of the document element so that it can be referred to and cancelled. This timer could then be subscribed to by any elements that need updating or trigger 'timeago_update' that could bubble up from the document.

@rmm5t
Copy link
Owner

rmm5t commented Oct 23, 2012

I think that's a good design change. Timeago is due for a small rewrite to accommodate suggestions like this and to accommodate other often requested features.

@Soviut
Copy link
Author

Soviut commented Oct 24, 2012

I wouldn't mind trying to help with that. Especially if we can adapt it to CoffeeScript as a pre-processing step.

@arcanis
Copy link

arcanis commented Nov 20, 2012

There is an problem with this : if, for example, there is a single 1-second element, and a thousand 1-month elements, using a single timer will trigger the event for every 1-month element at each second.

I think we should have a timer for each duration (1 second, 1 minute, 1 hour, 1 day, 1 week, 1 month, 1 year), each one having its own list of elements.

@Soviut
Copy link
Author

Soviut commented Nov 20, 2012

Not a bad idea. However, I assumed an object could do the same thing. Simply use second intervals as keys. I'm not sure which would be more efficient, but it would potentially keep the logic more centralized than several disparate timers.

var intervals = {
    1: [ ... ],
    60: [ ... ],
    3600: [ ... ],
    etc
}

mweibel pushed a commit to mila-labs/jquery-timeago that referenced this issue Mar 28, 2013
This commit will fix jquery.timeago's issue to have an interval
for each timeago element on a page.
By doing this it also removes destroyed elements automatically.

As such, this commit fixes rmm5t#96 and
rmm5t#90.
@rmm5t
Copy link
Owner

rmm5t commented Oct 2, 2013

Closing this out in favor of discussions on #90 and #122.

@rmm5t rmm5t closed this as completed Oct 2, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants