1

I got three js Files, AppView, NavigationMenuView, and HeaderView.

I'm trying to send an event to My HeaderView when a button is pressed in NavigationMenuView. Here is what I got so far. When I click a button in navigation view an event is emitted called "settings". Then Appview catches the Event. I have a hard time trying to get this event then passed to HeaderVew. Code Is below.

Thanks

AppView Code

function AppView() {
    View.apply(this, arguments);
    this.menuToggle = false;

    CreateHeaderView.call(this);
    CreateNavigatinMenuView.call(this);
    SetListeners.call(this);
}

AppView.prototype = Object.create(View.prototype);
AppView.prototype.constructor = AppView;

function CreateHeaderView() {
    this.HeaderView = new HeaderView();
    this.HeaderModifier = new StateModifier();

    this.add(this.HeaderModifier).add(this.HeaderView);
}

function CreateNavigatinMenuView() {
    this.NavigationView = new NavigationMenuView();
    this.NavigationViewModifier = new StateModifier();
    this.NavigationViewModifier.setTransform(
        Transform.translate(-dimensions[0], 0, 0), {}
        );

    this.add(this.NavigationViewModifier).add(this.NavigationView);
}

function SetListeners() {
    this.NavigationView.on('settings', function () {
        //HERE IS WHERE I WHOULD EMIT TO HEADER VIEW
    }.bind(this.HeaderView));
}

module.exports = AppView;

});

AppView

function SetListeners() {
    this.settingsButton.on('click', function () {
        this._eventOutput.emit('settings');
    }.bind(this));

}

HeaderView

  context.on('settings', function () {
    alert("Test");
}.bind(this));

1 Answers1

0

I'm assuming the second `SetListeners' is from NavigationMenuView (instead of AppView as mentioned above)?

I think in AppView, the code should be:

function SetListeners() {
    this.NavigationView.on('settings', function () {
        this.HeaderView._eventOutput.emit('settings');
    }.bind(this));
}

And in HeaderView:

this.on('settings, function () {
    // your code
}

The Timbre example on famo.us also contains good examples of event-piping: Timbre example

IjzerenHein
  • 2,690
  • 1
  • 17
  • 13