@@ -33,7 +33,7 @@ Elm.init = function(module, baseNode) {
3333
3434 // create the actuall RTS. Any impure modules will attach themselves to this
3535 // object. This permits many Elm programs to be embedded per document.
36− var elm = { notify: notify, node: baseNode };
36+ var elm = { notify: notify, node: baseNode, id: ElmRuntime.guid() };
3737
3838 // evaluate the given module and extract its 'main' value.
3939 signalGraph = module(elm).main;
@@ -65,10 +65,24 @@ Elm.init = function(module, baseNode) {
6565 }
6666
6767 signalGraph = A2(Signal.lift, domUpdate, signalGraph);
68+
69+ function send(name, value) {
70+ var e = document.createEvent('Event');
71+ e.initEvent(name + '_' + elm.id, true, true);
72+ e.value = value;
73+ document.dispatchEvent(e);
74+ }
75+ function recv(name, handler) {
76+ document.addEventListener(name + '_' + elm.id, handler);
77+ }
78+
79+ return { send : send, recv : recv };
6880};
6981
7082// Helper function to filter dead inputs. Not specific to initialization.
7183ElmRuntime = ElmRuntime || {};
84+ElmRuntime.counter = 0;
85+ElmRuntime.guid = function() { ++ElmRuntime.counter; return ElmRuntime.counter; }
7286ElmRuntime.filterDeadInputs = function() {
7387 'use strict';
7488 function isAlive(input) {