I’m working on a small application using cbWire 4.1 and ColdBox 7.3. Trying to use dispatchTo() to emit an event to another component. It doesn’t seem to be working or perhaps, I didn’t use the method correctly. Could someone lighten the shade? Thanks. @gcopley
addPost() was logged correctly. However, TopBar component didn’t get called.
Below is the code (improvised version from the cbWire docs) I use to try the method.
<cfoutput>
#wire("Posts")#
</cfoutput>
// ./wires/Posts.cfc
component extends="cbwire.models.Component" {
property name="log" inject="LogBox:logger:{this}";
function addPost() {
log.info("Add a new post and increment counter");
js('
console.log("Add a new post and increment counter");
');
dispatchTo( "TopBar", "post-added", {} );
}
function renderIt() {
return template("wires.posts");
}
}
<!--- ./wires/posts.cfm --->
<cfoutput>
<div>
<button class="btn btn-primary" wire:click="addPost">Add Post</button>
</div>
</cfoutput>
// ./wires/TopBar.cfc
component extends="cbwire.models.Component" {
property name="log" inject="LogBox:logger:{this}";
listeners = {
"post-added": "incrementPostCount"
};
function incrementPostCount() {
log.info("Increment the post count in TopBar");
js('
console.log("Increment the post count in TopBar");
');
}
}
<!--- ./wires/topBar.cfm --->
<cfoutput>
<div>
<!--- Empty --->
</div>
</cfoutput>