-
Notifications
You must be signed in to change notification settings - Fork 0
Description
When Time.delta
was added, the Now
and Last
newtypes¹ were created to force correct argument order (2a800e2). This works, but timestamps have utility outside of just Delta
s, and not having a way to get the current time as a Number
or access performance.now()
is frustrating.
I don't think Now
and Last
have to go, but at least exposing performance.now()
would be nice because I don't think any other libraries have it.
Here's a workaround using started
and stamp
:
started :: Effect Last
stamp :: forall a. Last -> (Delta -> a) -> Effect (Stamped a)
type Stamped a = { time :: Number, item :: a }
now :: Effect Number
now = started >>= (_ `stamp` const unit) >>> map _.time
¹ Originally Timestamp Now
and Timestamp Prev
. At one point, TimestampCurrent
and TimestampPrevious
.
Proposal
Add and export a function that gives the result of performance.now()
as a Number
instead of a newtype
.
Name?
now
is an obvious choice, but it's currently a key in Delta
and an obvious choice for pattern matching Now
values.
current
is probably fine, although I do like pnow
(silent p).