diff --git a/CHANGELOG.md b/CHANGELOG.md index f18a66d..bd89db5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Breaking changes: New features: Bugfixes: +- Changes the names of FFI timer functions to avoid naming clashes (#29 by @mikesol) Other improvements: diff --git a/src/Effect/Timer.js b/src/Effect/Timer.js index b535175..94436cd 100644 --- a/src/Effect/Timer.js +++ b/src/Effect/Timer.js @@ -1,5 +1,5 @@ /* no-redeclare global exports */ -export function setTimeout(ms) { +export function setTimeoutImpl(ms) { return function (fn) { return function () { return setTimeout(fn, ms); @@ -7,13 +7,13 @@ export function setTimeout(ms) { }; } -export function clearTimeout(id) { +export function clearTimeoutImpl(id) { return function () { clearTimeout(id); }; } -export function setInterval(ms) { +export function setIntervalImpl(ms) { return function (fn) { return function () { return setInterval(fn, ms); @@ -21,7 +21,7 @@ export function setInterval(ms) { }; } -export function clearInterval(id) { +export function clearIntervalImpl(id) { return function () { clearInterval(id); }; diff --git a/src/Effect/Timer.purs b/src/Effect/Timer.purs index 9394623..f6c180a 100644 --- a/src/Effect/Timer.purs +++ b/src/Effect/Timer.purs @@ -17,16 +17,22 @@ newtype TimeoutId = TimeoutId Int derive instance eqTimeoutId :: Eq TimeoutId derive instance ordTimeoutId :: Ord TimeoutId +foreign import setTimeoutImpl :: Int -> Effect Unit -> Effect TimeoutId + -- | Runs an effectful function after the specified delay in milliseconds. The -- | returned `TimeoutId` can be used to cancel the timer before it completes. -- | -- | The timeout delay value is capped at 4ms by the JS API, any value less than -- | this will be clamped. -foreign import setTimeout :: Int -> Effect Unit -> Effect TimeoutId +setTimeout :: Int -> Effect Unit -> Effect TimeoutId +setTimeout = setTimeoutImpl + +foreign import clearTimeoutImpl :: TimeoutId -> Effect Unit -- | Cancels a timeout. If the timeout has already been cancelled or has already -- | elapsed this will have no effect. -foreign import clearTimeout :: TimeoutId -> Effect Unit +clearTimeout :: TimeoutId -> Effect Unit +clearTimeout = clearTimeoutImpl -- | The ID of a timer started with `setInterval`. newtype IntervalId = IntervalId Int @@ -34,14 +40,20 @@ newtype IntervalId = IntervalId Int derive instance eqIntervalId :: Eq IntervalId derive instance ordIntervalId :: Ord IntervalId +foreign import setIntervalImpl :: Int -> Effect Unit -> Effect IntervalId + -- | Runs an effectful function after on a set interval with the specified delay -- | in milliseconds between iterations. The returned `IntervalId` can be used -- | to cancel the timer and prevent the interval from running any further. -- | -- | The interval delay value is capped at 4ms by the JS API, any value less -- | than this will be clamped. -foreign import setInterval :: Int -> Effect Unit -> Effect IntervalId +setInterval :: Int -> Effect Unit -> Effect IntervalId +setInterval = setIntervalImpl + +foreign import clearIntervalImpl :: IntervalId -> Effect Unit -- | Cancels an interval timer. If the interval has already been cancelled this -- | will have no effect. -foreign import clearInterval :: IntervalId -> Effect Unit +clearInterval :: IntervalId -> Effect Unit +clearInterval = clearIntervalImpl