-
11 Oct 2011 10:45 PM #1
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:
In our view, we have thefollowing snippet: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()); });
The code is successfully launched when we fire this event, but how can I access the variables in the view from this function?Code:initComponent: function() { var variable = "testme"; ...... ..... ..... Ext.ux.MessageBroker.on('message', function(record) { console.log(record.get('name')); });
Frank
-
12 Oct 2011 12:11 AM #2
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/


Reply With Quote