Skip to Content | Skip to Navigation


dojo.connectPublisher

Project owner:Alex Russell
since:V0.9

Ensure that every time an event is called, a message is published on the topic.

Introduction

dojo.connectPublisher is an automation of this common form:

[ Dojo 1.7 AMD ]

require(["dojo/_base/connect"], function(connect){
  connect.connect(myObject, "myEvent", function(){
    connect.publish("/some/topic/name", arguments);
  });
});

Which becomes:

require("dojo/_base/connect", function(connect){
  connect.connectPublisher("/some/topic/name", myObject, "myEvent");
});

[ Dojo < 1.7 ]

dojo.connect(myObject, "myEvent", function(){
     dojo.publish("/some/topic/name", arguments);
});

Which becomes:

dojo.connectPublisher("/some/topic/name", myObject, "myEvent");

Example

<script type="text/javascript">
  // Dojo 1.7 (AMD)
  require(["dojo/_base/connect"], function(connect){
     connect.connectPublisher("/ajax/start", dojo, "xhrGet");
  });
  // Dojo < 1.7
  dojo.connectPublisher("/ajax/start", dojo, "xhrGet");
</script>

API Info

full API:http://dojotoolkit.org/api/dojo/connectPublisher
summary:Ensure that every time obj.event() is called, a message is published on the topic. Returns a handle which can be passed to dojo.disconnect() to disable subsequent automatic publication on the topic.

Parameters

Signature

dojo.connectPublisher( /* String: */ topic,  /* Object|null: */ obj,  /* String: */ event)

Overview

  • topic String:

    The name of the topic to publish.

  • obj Object|null:

    The source object for the event function. Defaults to kernel.global if null.

  • event String:

    The name of the event function in obj. I.e. identifies a property obj[event].

Examples

dojo.connectPublisher(“/ajax/start”, dojo, “xhrGet”);