Skip to content

Commit 356a323

Browse files
Mike SolomonMike Solomonthomashoneyman
authored
Renames functions with underscore (#29)
* Renames functions with underscore * Updates from suggestions * Fixes formatting * Adds CHANGELOG entry * Update CHANGELOG.md Co-authored-by: Mike Solomon <[email protected]> Co-authored-by: Thomas Honeyman <[email protected]>
1 parent 0a40cdc commit 356a323

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Breaking changes:
99
New features:
1010

1111
Bugfixes:
12+
- Changes the names of FFI timer functions to avoid naming clashes (#29 by @mikesol)
1213

1314
Other improvements:
1415

src/Effect/Timer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
/* no-redeclare global exports */
2-
export function setTimeout(ms) {
2+
export function setTimeoutImpl(ms) {
33
return function (fn) {
44
return function () {
55
return setTimeout(fn, ms);
66
};
77
};
88
}
99

10-
export function clearTimeout(id) {
10+
export function clearTimeoutImpl(id) {
1111
return function () {
1212
clearTimeout(id);
1313
};
1414
}
1515

16-
export function setInterval(ms) {
16+
export function setIntervalImpl(ms) {
1717
return function (fn) {
1818
return function () {
1919
return setInterval(fn, ms);
2020
};
2121
};
2222
}
2323

24-
export function clearInterval(id) {
24+
export function clearIntervalImpl(id) {
2525
return function () {
2626
clearInterval(id);
2727
};

src/Effect/Timer.purs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,43 @@ newtype TimeoutId = TimeoutId Int
1717
derive instance eqTimeoutId :: Eq TimeoutId
1818
derive instance ordTimeoutId :: Ord TimeoutId
1919

20+
foreign import setTimeoutImpl :: Int -> Effect Unit -> Effect TimeoutId
21+
2022
-- | Runs an effectful function after the specified delay in milliseconds. The
2123
-- | returned `TimeoutId` can be used to cancel the timer before it completes.
2224
-- |
2325
-- | The timeout delay value is capped at 4ms by the JS API, any value less than
2426
-- | this will be clamped.
25-
foreign import setTimeout :: Int -> Effect Unit -> Effect TimeoutId
27+
setTimeout :: Int -> Effect Unit -> Effect TimeoutId
28+
setTimeout = setTimeoutImpl
29+
30+
foreign import clearTimeoutImpl :: TimeoutId -> Effect Unit
2631

2732
-- | Cancels a timeout. If the timeout has already been cancelled or has already
2833
-- | elapsed this will have no effect.
29-
foreign import clearTimeout :: TimeoutId -> Effect Unit
34+
clearTimeout :: TimeoutId -> Effect Unit
35+
clearTimeout = clearTimeoutImpl
3036

3137
-- | The ID of a timer started with `setInterval`.
3238
newtype IntervalId = IntervalId Int
3339

3440
derive instance eqIntervalId :: Eq IntervalId
3541
derive instance ordIntervalId :: Ord IntervalId
3642

43+
foreign import setIntervalImpl :: Int -> Effect Unit -> Effect IntervalId
44+
3745
-- | Runs an effectful function after on a set interval with the specified delay
3846
-- | in milliseconds between iterations. The returned `IntervalId` can be used
3947
-- | to cancel the timer and prevent the interval from running any further.
4048
-- |
4149
-- | The interval delay value is capped at 4ms by the JS API, any value less
4250
-- | than this will be clamped.
43-
foreign import setInterval :: Int -> Effect Unit -> Effect IntervalId
51+
setInterval :: Int -> Effect Unit -> Effect IntervalId
52+
setInterval = setIntervalImpl
53+
54+
foreign import clearIntervalImpl :: IntervalId -> Effect Unit
4455

4556
-- | Cancels an interval timer. If the interval has already been cancelled this
4657
-- | will have no effect.
47-
foreign import clearInterval :: IntervalId -> Effect Unit
58+
clearInterval :: IntervalId -> Effect Unit
59+
clearInterval = clearIntervalImpl

0 commit comments

Comments
 (0)