Skip to content

Allow "listeners" to be passed into constructor #777

@ScottMaclure

Description

@ScottMaclure

Use case: I like to create my "app" component, then use app.on() API to bind event handlers on component events. Example:

var app = new App({
    target: document.querySelector('main'),
    data: someData
})

// Example listener outside the component hierarchy.
app.on('deleteUser', (event) => {
    // etc...
})

Problem: In a nested component's oncreate method I might call this.fire('foo') but it's too early to use app.on() with and I miss that event.

So... what if I could pass in a map of event names -> functions to the "app" component's constructor? Or is there a better approach?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions