Send custom events using the Dojo framework

I use the Dojo framework to help me develop Javascript with cross-viewing DOM manipulation and event management.
For this, I was hoping to use custom event dispatching between objects. But I find nothing on this. I read about subscription / publication, but that is not quite what I want.
Here is what I would like to do:

var myObject = new CustomObject(); dojo.connect(myObject, 'onCustomEvent', function(argument) { console.log('custom event fired with argument : ' + argument); }); var CustomObject = (function() { CustomObject = function() { // Something which should look like this dojo.dispatch(this, 'onCustomEvent', argument); }; }) (); 

Can anybody help me?

Thanks.

+6
source share
1 answer

I usually do this as follows: (tested with Dojo 1.3.2)

 dojo.declare("CustomObject", null, { randomFunction: function() { // do some processing // raise event this.onCustomEvent('Random Argument'); }, onCustomEvent: function(arg) { } }); var myObject = new CustomObject(); dojo.connect(myObject, 'onCustomEvent', function(argument) { console.log('custom event fired with argument : ' + argument); }); // invoke the function which will raise the custom event myObject.randomFunction(); 
+3
source

Source: https://habr.com/ru/post/900595/


All Articles