Could you let me know why Tracker.autorun running twice?


#1

I tried use infinityScrolling on my app. I used Tracker.autorun when Template.onRendered and then i used session for PAGE_NUM. i give the Session parameter to Tracker. First render was perfect, Tracker code just run once. but when i go otherpage and then comeback, autorun was running twice. if i do again that increase Tracker running count as i re-visit… somebody have idea about this? i include my code.

initPage = ->
  $(window).scroll (event)->
    if ($(window).scrollTop() + $(window).height()) > ($(document).height() - 400)
      scrollTop = $(this).scrollTop()
      if scrollTop > @lastScrollTop
        sset 'PAGE_SEQ', (eval(sget('PAGE_SEQ')+'+'+1))
      @lastScrollTop = scrollTopi
      ...
 sset 'PAGE_SEQ' , 1  #

---- Template Methods—

> Template.templateName.onRendered ->

>   initPage()

>   Tracker.autorun ->
>     if (sget('PAGE_SEQ'))
>       getProduct()



Template.templateName.onDestroyed ->

  console.log '디스트로이드'
  delete Session.keys['nameSticker']
  delete Session.keys['MTRL_COD']
  delete Session.keys['SIZE_NME']
  delete Session.keys['THO_COD']
  delete Session.keys['ADD_TXT_CNT']
  delete Session.keys['CATE_COD']
  delete Session.keys['CATE_DTL_COD']
  delete Session.keys['BNC_GBN']
  delete Session.keys['PAGE_SEQ']
  delete Session.keys['TMPL_NME']