Only use a single timer/setInterval #96

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

Comments

Projects
None yet
3 participants
@Soviut

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

This comment has been minimized.

Show comment Hide comment
@rmm5t

rmm5t Oct 23, 2012

Owner

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.

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

This comment has been minimized.

Show comment Hide comment
@Soviut

Soviut 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.

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

This comment has been minimized.

Show comment Hide comment
@arcanis

arcanis 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.

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

This comment has been minimized.

Show comment Hide comment
@Soviut

Soviut 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
}

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

Michael Weibel
Implemented only one Interval on a page.
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/jquery-timeago#96 and
rmm5t/jquery-timeago#90.
@rmm5t

This comment has been minimized.

Show comment Hide comment
@rmm5t

rmm5t Oct 2, 2013

Owner

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

Owner

rmm5t commented Oct 2, 2013

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

@rmm5t rmm5t closed this Oct 2, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment