Skip to content

Commit

Permalink
Make signals always distinct (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdp authored May 21, 2020
1 parent 59a1c2b commit 740f39c
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/Wire/Signal.purs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ newtype Signal a
, write :: a -> Effect Unit
}

create :: forall a. a -> Effect { signal :: Signal a, cancel :: Effect Unit }
create :: forall a. Eq a => a -> Effect { signal :: Signal a, cancel :: Effect Unit }
create init = do
value <- Ref.new init
inner <- Event.create
Expand All @@ -25,7 +25,7 @@ create init = do

modify' f = Ref.modify f value >>= inner.push

signal = Signal { event: inner.event, read: read', write: write', modify: modify' }
signal = Signal { event: Event.distinct inner.event, read: read', write: write', modify: modify' }
pure { signal, cancel: inner.cancel }

subscribe :: forall a. Signal a -> Subscriber a -> Effect Canceler
Expand All @@ -44,6 +44,3 @@ write a (Signal s) = s.write a

modify :: forall a. (a -> a) -> Signal a -> Effect Unit
modify f (Signal s) = s.modify f

distinct :: forall a. Eq a => Signal a -> Signal a
distinct (Signal s) = Signal s { event = Event.distinct s.event }

0 comments on commit 740f39c

Please sign in to comment.