Skip to content

Event handlers run multiple times when using >1 stores #32

@vaughnd

Description

@vaughnd

Hi, I'm on riot 2.4.1 and riotcontrol 0.0.3. I'm using webpack to transpile es7.

I'm running into problems with event handlers being fired multiple times after a single event trigger. It seems to be related to my use of multiple stores and riot.observable(this) in the constructor, but I'm not sure how to do it differently. After looking through the other issues, someone suggested using a single broker = riot.observable(); for all stores, but I'm not sure how to get that working.

My handler is definitely added only once, and commenting out the riot.observable(this) in stores reduces the number of times the event is fired.

class AutoCompleteStore {
    constructor() {
        riot.observable(this);
    }
}

let autoCompleteStore = new AutoCompleteStore();
riot.control.addStore(autoCompleteStore);
export default autoCompleteStore;

In my page tag:

let changeResultsHandler = () => {
    console.info("changeResultsHandlerFired");
    this.update();
}
this.on('mount', () => {
    riot.control.on(riot.EVT.changeResults, changeResultsHandler);
    riot.control.trigger(riot.EVT.changeResults);
});

this.on('unmount', () => {
    riot.control.off(riot.EVT.changeResults, changeResultsHandler);
});

Am I using the correct patterns here?

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