javascript - Best strategy to maintain a sorted list subject to realtime updates -


i'm building html list similar facebooks timeline feature. list ontain @ 100 items, performance isn't requirement.

unlike facebook's timeline however, list quite dynamic. example different events arrive in realtime , depending on timestamp, might prepended list, inserted (i can't guarantee new events arrive in time order) , removed. on top of that, nice animate updating of list (add/inser/remove) too, that's separate issue.

i wonder best strategy maintain list (sorted time of course), once i've built initial data?

thanks.

as suggested in other answer, have data-time property on each element. when new data arrives, locate first element data().time lesser new time. if there such element, use element.before(newelement), otherwise container.append(newelement). way list kept sorted.

illustration: http://jsfiddle.net/jxlgr/


Comments

Popular posts from this blog

java - How to Configure JAXRS and Spring With Annotations -

visual studio - TFS will not accept changes I've made to a Java project -

php - Create image in codeigniter on the fly -