Skip to content

Renames functions with underscore #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
8 changes: 4 additions & 4 deletions src/Effect/Timer.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
/* no-redeclare global exports */
export function setTimeout(ms) {
export function setTimeoutImpl(ms) {
return function (fn) {
return function () {
return setTimeout(fn, 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);
};
};
}

export function clearInterval(id) {
export function clearIntervalImpl(id) {
return function () {
clearInterval(id);
};
Expand Down
20 changes: 16 additions & 4 deletions src/Effect/Timer.purs
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,43 @@ 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

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