@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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jdeighan/coffee-utils",
3
3
  "type": "module",
4
- "version": "4.1.27",
4
+ "version": "4.1.28",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -1,6 +1,7 @@
1
1
  # svelte_utils.coffee
2
2
 
3
- import {onDestroy} from 'svelte'
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
- interval = setInterval(func, Math.floor(1000 * secs))
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
- onDestroy () ->
38
+ return () ->
39
+ if doLog
40
+ log "destroying interval timer"
34
41
  clearInterval interval
@@ -1,8 +1,13 @@
1
1
  // Generated by CoffeeScript 2.6.1
2
2
  // svelte_utils.coffee
3
3
  import {
4
- onDestroy
5
- } from 'svelte';
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
- interval = setInterval(func, Math.floor(1000 * secs));
23
- return onDestroy(function() {
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
  };