Riot: Observable event handler: can't use direct reference to tag.update in @next

Created on 28 Oct 2016  路  3Comments  路  Source: riot/riot

Describe your issue:

I'm not sure if this is by design or a bug. Setting an observable event handler directly to the tag's update method - e.g. using obs.on('event', this.update) inside a tag - causes expression parsing to break when the event is triggered asynchronously (expressions incorrectly evaluate to null).

This only occurs in @next, and used to work fine in 2.x.

Can you reproduce the issue?

http://plnkr.co/edit/liZ9RHSgmvkwVynstegU?p=preview

  • The following fixes it on @next:

Switching this.opts.model.on('emit', this.update); to:

this.opts.model.on('emit', function(){
        _this.update();
    });

However, with this approach, we can no longer unregister the handler since it's an anonymous function. The obvious workaround is to make a separate method: eventHandler(){ _this.update() } but it seems like overkill for such a common use case.

  • Another thing which fixes it: if the emit is synchronous (remove setTimeout on line 20 of my-tag.html). edit: _Actually, this no longer works for me, not sure why._

On which browser/OS does the issue appear?

Chrome / Windows 10 64-bit
Safari / iOS 10

Which version of Riot does it affect?

@next

How would you tag this issue?

  • [x] Question
  • [x] Bug
  • [ ] Discussion
  • [ ] Feature request
  • [ ] Tip
  • [ ] Enhancement
  • [ ] Performance
bug fixed

All 3 comments

thank you, this seems to be a bug!

Brilliant, thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

laznic picture laznic  路  3Comments

jfbrennan picture jfbrennan  路  3Comments

danawoodman picture danawoodman  路  3Comments

vogloblinsky picture vogloblinsky  路  3Comments

SatoshiKawabata picture SatoshiKawabata  路  3Comments