Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a variable update work in riot js

Loving riot js but why is "Hello 0" not incrementing on the page in the following code example, and what is the workaround for now?

<my-app>
    <p>Hello {myNumber}</p>
    this.myNumber = 0;
    var thisApp = this;
    setInterval(
        function(){
            thisApp.myNumber++;
        },
        1000
    );
</my-app>
like image 748
Navigateur Avatar asked Dec 24 '22 17:12

Navigateur


1 Answers

Inside the function add

thisApp.update();

There is no way to add and configure dirty checking in riot js, as of version 2.2.2-beta.

You don't need to call update() in the execution of your

  1. outermost script
  2. event functions executed via riot js html template expressions

...because riot js automatically calls update() after executing those.

like image 109
Navigateur Avatar answered Jan 02 '23 07:01

Navigateur