diff --git a/src/FRP/Event.js b/src/FRP/Event.js index f159412..7809ddf 100644 --- a/src/FRP/Event.js +++ b/src/FRP/Event.js @@ -144,7 +144,7 @@ exports.keepLatest = function (e) { }; }; -function subject() { +exports.create = function () { var subs = []; return { event: function(sub) { @@ -157,19 +157,24 @@ function subject() { }; }, push: function(a) { - for (var i = 0; i < subs.length; i++) { - subs[i](a); - } + return function() { + for (var i = 0; i < subs.length; i++) { + subs[i](a); + } + }; } }; }; exports.fix = function(f) { - var s = subject(); + var s = exports.create(); var io = f(s.event); return function(sub) { - var cancel1 = io.input(s.push); + var sub1 = function(a) { + s.push(a)(); + }; + var cancel1 = io.input(sub1); var cancel2 = io.output(sub); return function() { diff --git a/src/FRP/Event.purs b/src/FRP/Event.purs index 2e80196..e217c58 100644 --- a/src/FRP/Event.purs +++ b/src/FRP/Event.purs @@ -1,5 +1,6 @@ module FRP.Event ( Event + , create , subscribe , module Class ) where @@ -107,3 +108,11 @@ foreign import subscribe . Event a -> (a -> Eff (frp :: FRP | eff) r) -> Eff (frp :: FRP | eff) (Eff (frp :: FRP | eff) Unit) + +-- | Create an event and a function which supplies a value to that event. +foreign import create + :: forall eff a + . Eff (frp :: FRP | eff) + { event :: Event a + , push :: a -> Eff (frp :: FRP | eff) Unit + }