sendWidgetAction and Event not binding `this` to widget


(Sam Saffron) #1

This is mainly for @eviltrout but would have implications to all plugin devs.

At the moment sendWidgetAction and Event is not binding this to the widget.

sendWidgetAction(name, param) {
    return this.rerenderResult(() => {
      const widget = this._findAncestorWithProperty(name);
      if (widget) {
        return widget[name](param);
      }

      return this._sendComponentAction(name, param || this.findAncestorModel());
    });
  }

In particular we have

      if (widget) {
        return widget[name](param);
      }

Instead this could be:

     if (widget) {
        return widget[name].call(widget, param);
      }

Is there and reason we should not make this change?


(Robin Ward) #2

This seems totally sensible to me. You’d expect a widget’s method to have this pointing to itself. I doubt there are any plugins that counted on this pointing at something else, and if so that’s confusing and they should be updated.

I’ve made the change: