1. #1
    Ext JS Premium Member
    Join Date
    Jan 2011
    Location
    NORWAY
    Posts
    106
    Vote Rating
    0
    frankbolviken is an unknown quantity at this point

      0  

    Default Unanswered: Messagebus

    Unanswered: Messagebus


    Hello,

    We want to implement a MessageBus as we can't see that it's ootb?
    We found a user extension:

    Code:
    Ext.define('Ext.ux.MessageBroker', {    extend: 'Ext.util.Observable',
    
    
        statics: {
            instance: null,
            setInstance: function(i) {
                this.instance = i;
            },
            sendMessage: function(msg, data) {
                this.fireEvent(msg,data);
            }
        },
    
    
        constructor: function(config){
            this.addEvents({
                "message" : true
            });
    
    
            if(config && config.listeners) this.listeners = config.listeners;
    
    
            Ext.ux.MessageBroker.superclass.constructor.call(this, config)
        }
    
    
    }, function() {
        Ext.ux.MessageBroker.setInstance(new Ext.ux.MessageBroker());
    });
    In our view, we have thefollowing snippet:
    Code:
    initComponent: function() {
    		var variable = "testme";
    ......
    .....
    .....
    
    
    Ext.ux.MessageBroker.on('message', function(record) {			console.log(record.get('name'));
    });
    The code is successfully launched when we fire this event, but how can I access the variables in the view from this function?

    Frank

  2. #2
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,492
    Answers
    526
    Vote Rating
    283
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      0  

    Default


    Your question is a little ambiguous. It isn't clear whether the line that registers the listener is inside or outside of initComponent. If it's inside then you can just reference your variables by name. If it's outside then you can't access them directly, you'll need to save them somewhere, e.g. on this.

    Not sure where you found that UX but here are a few thoughts about it...

    I think it could be simplified a lot using singleton: true.

    http://docs.sencha.com/ext-js/4-0/#!...-cfg-singleton

    It shouldn't need to copy the listeners to this, that should already be done by the superconstructor.

    To call the superconstructor it should use this.callParent(arguments), the way it does it currently is the ExtJS 3 way.

    An alternative approach to writing your own MessageBus would be to use application events, as discussed at the end of this article:

    http://www.sencha.com/learn/architec...t-js-4-part-2/

Thread Participants: 1