@jdeighan/coffee-utils 4.1.27 → 4.1.28
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/src/svelte_utils.coffee +11 -4
- package/src/svelte_utils.js +20 -7
package/package.json
CHANGED
package/src/svelte_utils.coffee
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# svelte_utils.coffee
|
2
2
|
|
3
|
-
import {
|
3
|
+
import {assert, isFunction} from '@jdeighan/coffee-utils'
|
4
|
+
import {log} from '@jdeighan/coffee-utils/log'
|
4
5
|
|
5
6
|
# ---------------------------------------------------------------------------
|
6
7
|
# svelteSourceCodeEsc - to display source code for a *.starbucks page
|
@@ -26,9 +27,15 @@ export svelteHtmlEsc = (str) ->
|
|
26
27
|
|
27
28
|
# ---------------------------------------------------------------------------
|
28
29
|
|
29
|
-
export onInterval = (func, secs) ->
|
30
|
+
export onInterval = (func, secs, doLog=false) ->
|
30
31
|
|
31
|
-
|
32
|
+
assert isFunction(func), "onInterval(): 1st arg not a function"
|
33
|
+
ms = Math.floor(1000 * secs)
|
34
|
+
if doLog
|
35
|
+
log "calling func every #{ms} ms."
|
36
|
+
interval = setInterval(func, ms)
|
32
37
|
|
33
|
-
|
38
|
+
return () ->
|
39
|
+
if doLog
|
40
|
+
log "destroying interval timer"
|
34
41
|
clearInterval interval
|
package/src/svelte_utils.js
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
// Generated by CoffeeScript 2.6.1
|
2
2
|
// svelte_utils.coffee
|
3
3
|
import {
|
4
|
-
|
5
|
-
|
4
|
+
assert,
|
5
|
+
isFunction
|
6
|
+
} from '@jdeighan/coffee-utils';
|
7
|
+
|
8
|
+
import {
|
9
|
+
log
|
10
|
+
} from '@jdeighan/coffee-utils/log';
|
6
11
|
|
7
12
|
// ---------------------------------------------------------------------------
|
8
13
|
// svelteSourceCodeEsc - to display source code for a *.starbucks page
|
@@ -17,10 +22,18 @@ export var svelteHtmlEsc = function(str) {
|
|
17
22
|
};
|
18
23
|
|
19
24
|
// ---------------------------------------------------------------------------
|
20
|
-
export var onInterval = function(func, secs) {
|
21
|
-
var interval;
|
22
|
-
|
23
|
-
|
25
|
+
export var onInterval = function(func, secs, doLog = false) {
|
26
|
+
var interval, ms;
|
27
|
+
assert(isFunction(func), "onInterval(): 1st arg not a function");
|
28
|
+
ms = Math.floor(1000 * secs);
|
29
|
+
if (doLog) {
|
30
|
+
log(`calling func every ${ms} ms.`);
|
31
|
+
}
|
32
|
+
interval = setInterval(func, ms);
|
33
|
+
return function() {
|
34
|
+
if (doLog) {
|
35
|
+
log("destroying interval timer");
|
36
|
+
}
|
24
37
|
return clearInterval(interval);
|
25
|
-
}
|
38
|
+
};
|
26
39
|
};
|