in Famo.us, how do you pipe events to parent view from inside parent view

115 views Asked by At

I have a custom view that contains a surface. I am needing to pipe the surface events to the parent view. I can do this easily from outside the view, but how do I do this from inside the view? Here is my custom view with the code that does NOT work:

define([
    "famous/core/view",
    "famous/core/Surface",
    "famous/modifiers/StateModifier"
], function(View, Surface, StateModifier){

    function _createContainer() {
        var self = this;
        var container = new Surface({
            classes: ['blue-bg'],
            content: 'HERE IS A LOVELY BIT OF CONTENT FOR MY SURFACE'
        });
        // THIS DOESN'T WORK, BUT ILLUSTRATES WHAT I'M NEEDING TO DO:
        container.pipe(self);
        self.containerNode.add(container);
        self.form = container;
    }

    function FormView(){
        var self = this;
        View.apply(self, arguments);
        var containerMod = new StateModifier({
            size: self.options.size
        });
        self.containerNode = self.add(containerMod);
        _createContainer.call(self);
    }

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

    FormView.DEFAULT_OPTIONS = {
        size: [300, 800]
    };

    return FormView;
});

Here is example code that does work, but that I want to do from inside the view:

var myView = new View();
mainContext.add(myView);

var surface = new Surface({
  size: [100, 100],
  content: 'click me',
  properties: {
    color: 'white',
    textAlign: 'center',
    backgroundColor: '#FA5C4F'
  }
});

myView.add(surface);

surface.pipe(myView);
1

There are 1 answers

3
talves On BEST ANSWER

Inside your custom view FormView you need to pipe to the view's event handler. This will allow the view's events to be seen by a Scrollview when they are added to surfaces.

Change

container.pipe(self);

to

container.pipe(self._eventOutput);