Riot: Prevent update from being called after event handler

Created on 6 Aug 2015  路  3Comments  路  Source: riot/riot

When an event handler of a tag gets triggered, Riot currently calls the update() method automatically. Depending on the use case, this might actually not be desirable, for instance when listening to an onkeyup event like so:

<paragraphs-tag>
  {console.log("this will be rerendered with every keystroke in the input field")}

  <p each={paragraph in self.paragraphs}>
    {paragraph}
  </p>
  <input onkeyup="keyhandler" />

  <script>
    keyhandler(e) {
      //it would be nice if there was a way to decide
      //here whether updating the view is necessary
    }
  </script>

</paragraphs-tag>
answered question

Most helpful comment

Thanks a bunch! Maybe it would be a good idea to highlight the existence of e.preventUpdate simply by using the code format on it so that it can be found more easily while scanning the documentation for information.

All 3 comments

Have you tried e.preventUpdate = true? https://muut.com/riotjs/guide/#tag-lifecycle

Thanks a bunch! Maybe it would be a good idea to highlight the existence of e.preventUpdate simply by using the code format on it so that it can be found more easily while scanning the documentation for information.

shouldn't be e.preventUpdate = true be e.preventUpdate() like e.preventDefault() and e.preventPropagate is implemented in the standards?

More info would be awesome regarding this decision. Thanks in advance @GianlucaGuarini !

Was this page helpful?
0 / 5 - 0 ratings