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

Playground: clearInterval is never executed in Timer sample (#15) #168

Open
jakub-g opened this issue May 6, 2014 · 1 comment
Open
Labels

Comments

@jakub-g
Copy link
Collaborator

jakub-g commented May 6, 2014

Here's the code from timer.hsp:

var Timer=klass({
...
    $init:function() {
      this.secondsElapsed=this.initvalue;
      this._iid=setInterval(this.tick.bind(this),1000);
    },
    $dispose:function() {
      clearInterval(this._iid);
    },
    tick:function() {
      console.log("tick");
      this.secondsElapsed++;
      this.$dispose();
    }
});

When you actually open console and play with the sample, you can see that the interval is never cleared, so it will be logging stuff ad infinitum once you've visited sample #15. If you start playing with the code, it gets even worse, because every character you type, the template is recompiled and new interval is established, hence the number of listeners grows with each keystroke.

BTW we have the same kind of issue with InstantAT: when someone creates an @aria:Dialog in his instant, with each keystroke in his template, a new dialog is created and put in front, while the old dialog is not destroyed ( juliandescottes/instantat#16 )

@jakub-g jakub-g added the bug label May 6, 2014
@b-laporte
Copy link
Member

Yes - I know this problem for a while. Actually this is linked to a more general problem on how template disposal should be managed.

Today application developers have to explicitely call $dispose(). And the problem of the playground is that samples don't manage the 'output' div (and the playground doesn't know which template is currently displayed). So I was thinking of adding an optional feature (activated by default) so that when calling render() on a template, it would automatically dispose any template currently displayed in the same HTML container (cf. backlog)..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants