D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
jamesleesaunders
Full window
Github gist
D3 : Dispatch
Dispatch
<!DOCTYPE html> <head> <title>D3 Lesson 32 : Dispatch</title> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js" charset="utf-8"></script> </head> <body> <h1>D3 Dispatch Example</h1> <div id="holder1"></div> <div id="holder2"></div> <script> // Documentation: https://github.com/mbostock/d3/wiki/Internals#events // This is an implementation of the publish/subscribe pattern // e.g. https://addyosmani.com/resources/essentialjsdesignpatterns/book/#observerpatternjavascript // Create a dispatcher object var myDispatch = d3.dispatch('countrySelect'); // Set up event handlers for when countrySelect event is fired myDispatch.on('countrySelect.sub1', function(country) { console.log(country, 'selected (1)'); d3.select('#holder1').html('1: ' + country + ' Selected'); }); myDispatch.on('countrySelect.sub2', function(country) { console.log(country, 'selected (2)'); d3.select('#holder2').html('2: ' + country + ' Selected'); }); // Trigger the event myDispatch.countrySelect('France'); </script> </body> </html>
https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js