Search code examples
javascriptdojodom-events

dojox drawing rectangle connect method


Dojox drawing api has rectangle as stencil which we can use on a drawing canvas. The docs mentions about a function called connect. how do i use it? connect(o, e, s, m, once)

Following is available in uncompressed dojo code.

// TODO: connect to a Shape event from outside class
connect: function(o, e, s, m, /* Boolean*/once){
// summary:
//      Convenience method for quick connects
//      See comments below for possiblities
//      functions can be strings
// once:
//      If true, the connection happens only
//      once then disconnects. Five args are required
//      for this functionality.

It is not clear why and how to use this function. Could some help me with the usage and functionality of the function.


Solution

  • The first four methods are passed to dojo.connect.

    https://dojotoolkit.org/reference-guide/1.6/dojo/connect.html#usage

    • o - object
    • e - event
    • s - scope or context
    • m - method

    Connect the event of this object to the method with the scope.

    dojo.connect(domNode, 'click', { test: 1}, function() {
      var t = this test;
      // is one because 'this' is the scope we pass the connect method. 
    });
    

    The function will be executed every time the particular dom node is clicked on.

    The last argument once is specific to the convenience method. If true, the function will be executed only once. After being executed, the handler will be disconnected.