on master help sign in
Add send and recv functions for each RTS instance.
f49a509evancz
runtime/Init.js+15−1
@@ -33,7 +33,7 @@ Elm.init = function(module, baseNode) {
33
33
34 // create the actuall RTS. Any impure modules will attach themselves to this
34 // create the actuall RTS. Any impure modules will attach themselves to this
35 // object. This permits many Elm programs to be embedded per document.
35 // 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() };
37
37
38 // evaluate the given module and extract its 'main' value.
38 // evaluate the given module and extract its 'main' value.
39 signalGraph = module(elm).main;
39 signalGraph = module(elm).main;
@@ -65,10 +65,24 @@ Elm.init = function(module, baseNode) {
65 }
65 }
66
66
67 signalGraph = A2(Signal.lift, domUpdate, signalGraph);
67 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 };
68};
80};
69
81
70// Helper function to filter dead inputs. Not specific to initialization.
82// Helper function to filter dead inputs. Not specific to initialization.
71ElmRuntime = ElmRuntime || {};
83ElmRuntime = ElmRuntime || {};
84+ElmRuntime.counter = 0;
85+ElmRuntime.guid = function() { ++ElmRuntime.counter; return ElmRuntime.counter; }
72ElmRuntime.filterDeadInputs = function() {
86ElmRuntime.filterDeadInputs = function() {
73 'use strict';
87 'use strict';
74 function isAlive(input) {
88 function isAlive(input) {