Event handler for custom event does not work, without rendering the hoster component

edited March 2013 in Newbie Questions
Hello,

This code work as expected - two events after clicking the button in debug console.
enyo.kind({
    name: 'Igotta.Chat',
    components: [{ kind: 'Button', content: 'Click Me!', ontap: '_addMessageOnTap' }],
    events: {
        onMessageAdd: ""
    },

    _addMessageOnTap: function (inSource, inEvent) {
        console.log(inEvent);
        this.doMessageAdd({ messageText: 'test' });
    }
});


enyo.kind({
    name: 'Igotta.ChatApp',
    components: [{ kind: 'Igotta.Chat', name: 'Chat', onMessageAdd: 'onMessageAddHandler' }],
    onMessageAddHandler: function (inSender, inEvent) {
        console.log(inEvent);
    }
});


var charApp = new Igotta.ChatApp().renderInto(document.body);

How to make 'Igotta.ChatApp' control not rendering? This don't work - onMessageAddHandler don't work:
// Igotta.Chat - the same
...


enyo.kind({
    name: 'Igotta.ChatApp',
    kind: enyo.Component,
    components: [{ kind: 'Igotta.Chat', name: 'Chat', onMessageAdd: 'onMessageAddHandler ' }],
    onMessageAddHandler : function (inSender, inEvent) {
        console.log(inEvent);
    }
});

var charApp = new Igotta.ChatApp();
charApp.$.Chat.renderInto(document.body);
I want to keep HTML in 'Igotta.Chat', 'Igotta.ChatApp' should not display anything, only 'Igotta.Chat' html.

Thanks.

Comments

  • edited March 2013
    It's work, but is it the right way:
    enyo.kind({
        name: 'Igotta.ChatApp',
        //kind: 'Component',
        components: [{ kind: 'Igotta.Chat', name: 'Chat', onMessageAdd: 'onMessageAddHandler' }],
        onMessageAddHandler: function (inSender, inEvent) {
            console.log(inEvent);
        },
        renderChat: function () {
            this.$.Chat.renderInto(document.body);
        }
    });
    
    
    var chatApp = new Igotta.ChatApp();
    chatApp.renderChat();
    
  • That can work. I'm not sure why you commented out the kind: "Component" line, the default kind is "Control" but chatApp won't actually be rendered because you're bypassing that.

    The new MVC support has an "Application" kind that simplifies this structure, but setting up a "view" component that's the one rendered, while the app object is non-rendered and holds controllers.
Sign In or Register to comment.