Skip to content

refactor widget event notification #6

@wkeese

Description

@wkeese

Remove all the onFoo() stub methods in widgets, or perhaps put them in doc comments so that the doc parser still picks them up.

Simplify _WidgetBase.on() to just delegate to listening for specified event on this.domNode. Code is already there, so it's just a question of removing _onMap() and the code that calls it.

Make all widgets call _WidgetBase.emit() whenever an event occurs, rather than calling the stub function directly.
For native events, like clicking a button, widgets don't need to do anything, except perhaps stop the event if the widget is disabled.

Finally, similar to how _Widget works with this._toConnect (in constructor() and postCreate(), make way so events specified to widget constructors (ex: new Button({onClick: ...}) get mapped to _WidgetBase.on() calls.

Open issues:

  1. Do we need to make exceptions for functions that should be directly assigned to the this, rather than using on()? Doug is always big on onClick() returning a true/false value that can stop event propagation. Maybe there are other cases too.
  2. Also might be nice for backwards-compatibility to keep the code in _WidgetBase.on() that sets up advice on a stub function if it exists, rather than listening for events on the DOMNode. Since that's still considered the standard way for widgets to emit events.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions