@kizmann/pico-js 2.0.4 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,87 +1,73 @@
1
1
  export class PicoRunner {
2
- static $idler: {
3
- native: {};
4
- debounce: {};
5
- throttle: {};
6
- };
7
- static $timer: {
8
- date: number;
9
- func: any;
10
- };
2
+ static $idler: any;
3
+ static $timer: number;
11
4
  static $buffer: any[];
12
5
  /**
13
- * Run callback after delay (id)
6
+ * Clear timer or call function
14
7
  *
15
- * @example Run.timeout(() => {}, 100) // => "t-..."
8
+ * @example Run.clear(timer)
16
9
  *
17
- * @param {function} fn Callback to run
18
- * @param {number} [delay] Delay ms
19
- * @param {string|null} [index] Timer id
20
- * @returns {string} Timer id
10
+ * @param {any} timer Timer ID, array of IDs, or function
11
+ * @returns {typeof PicoRunner} Static class
21
12
  */
22
- static timeout(fn: Function, delay?: number, index?: string | null): string;
13
+ static clear(timer: any): typeof PicoRunner;
23
14
  /**
24
- * Run callback on interval (id)
25
- *
26
- * @example Run.interval(() => {}, 250) // => "i-..."
15
+ * Request idle callback with fallback
27
16
  *
28
- * @param {function} fn Callback to run
29
- * @param {number} [intval] Interval ms
30
- * @param {string|null} [index] Timer id
31
- * @returns {string} Timer id
17
+ * @param {function} cb Callback function
18
+ * @returns {typeof PicoRunner} Static class
32
19
  */
33
- static interval(fn: Function, intval?: number, index?: string | null): string;
20
+ static tryin(cb: Function): typeof PicoRunner;
34
21
  /**
35
- * Clear timer(s) by id
22
+ * Wait for condition to be true
36
23
  *
37
- * @example Run.clear("i-abc") // => Run
38
- * @example Run.clear(["t-a","i-b"]) // => Run
24
+ * @example Run.wait(() => window.foo, 10, 100)
39
25
  *
40
- * @param {string|Array<string>} index Timer id(s)
41
- * @param {string} [scope] Idler scope key
42
- * @returns {typeof PicoRunner} Runner class
26
+ * @param {function} fn Condition function
27
+ * @param {number} [intval] Interval ms
28
+ * @param {number} [limit] Max iterations
29
+ * @returns {function} Clear function
43
30
  */
44
- static clear(index: string | Array<string>, scope?: string): typeof PicoRunner;
31
+ static wait(fn: Function, intval?: number, limit?: number): Function;
45
32
  /**
46
- * Poll until callback is true
33
+ * Run function in next animation frame
47
34
  *
48
- * @example Run.wait(() => ready, 50) // polls
35
+ * @example Run.frame(cb)
49
36
  *
50
- * @param {function} fn Condition callback
51
- * @param {number} [intval] Poll interval ms
52
- * @param {number} [limit] Max poll count
53
- * @returns {void} No return value
37
+ * @param {function} fn Callback function
38
+ * @param {any} [...args] Callback arguments
39
+ * @returns {function} Noop clear function
54
40
  */
55
- static wait(fn: Function, intval?: number, limit?: number): void;
41
+ static frame(fn: Function, ...args: any[]): Function;
56
42
  /**
57
- * Run callback in next frame
43
+ * Run function when browser is idle
58
44
  *
59
- * @example Run.frame(() => {}) // => Run
45
+ * @example Run.idle(cb)
60
46
  *
61
- * @param {function} fn Callback to run
62
- * @param {...any} args Callback args
63
- * @returns {typeof PicoRunner} Runner class
47
+ * @param {function} fn Callback function
48
+ * @param {any} [...args] Callback arguments
49
+ * @returns {function} Noop clear function
64
50
  */
65
- static frame(fn: Function, ...args: any[]): typeof PicoRunner;
51
+ static idle(fn: Function, ...args: any[]): Function;
66
52
  /**
67
- * Run callback async soon
53
+ * Run function asynchronously
68
54
  *
69
- * @example Run.async(() => {}) // => Run
55
+ * @example Run.async(cb)
70
56
  *
71
- * @param {function} fn Callback to run
72
- * @param {...any} args Callback args
73
- * @returns {typeof PicoRunner} Runner class
57
+ * @param {function} fn Callback function
58
+ * @param {any} [...args] Callback arguments
59
+ * @returns {function} Noop clear function
74
60
  */
75
- static async(fn: Function, ...args: any[]): typeof PicoRunner;
61
+ static async(fn: Function, ...args: any[]): Function;
76
62
  /**
77
- * Run callback after delay
63
+ * Run function after delay
78
64
  *
79
- * @example const cancel = Run.delay(() => {}, 50)
65
+ * @example Run.delay(cb, 100)
80
66
  *
81
- * @param {function} fn Callback to run
67
+ * @param {function} fn Callback function
82
68
  * @param {number} [delay] Delay ms
83
- * @param {...any} args Callback args
84
- * @returns {function} Cancel function
69
+ * @param {any} [...args] Callback arguments
70
+ * @returns {function} Clear function
85
71
  */
86
72
  static delay(fn: Function, delay?: number, ...args: any[]): Function;
87
73
  /**
@@ -91,10 +77,9 @@ export class PicoRunner {
91
77
  *
92
78
  * @param {function} cb Callback to run
93
79
  * @param {number} [timeout] Wait ms
94
- * @param {string|null} [index] Debounce id
95
80
  * @returns {function} Debounced fn
96
81
  */
97
- static debounce(cb: Function, timeout?: number, index?: string | null): Function;
82
+ static debounce(cb: Function, timeout?: number): Function;
98
83
  /**
99
84
  * Create throttled callback
100
85
  *
@@ -102,10 +87,9 @@ export class PicoRunner {
102
87
  *
103
88
  * @param {function} cb Callback to run
104
89
  * @param {number} [timeout] Wait ms
105
- * @param {string|null} [index] Throttle id
106
90
  * @returns {function} Throttled fn
107
91
  */
108
- static throttle(cb: Function, timeout?: number, index?: string | null): Function;
92
+ static throttle(cb: Function, timeout?: number): Function;
109
93
  /**
110
94
  * Create framerate-limited callback
111
95
  *
@@ -123,10 +107,10 @@ export class PicoRunner {
123
107
  *
124
108
  * @param {function} cb Callback to run
125
109
  * @param {string} key Buffer key
126
- * @param {number} [order] Sort order
110
+ * @param {number} [priority] Sort priority
127
111
  * @returns {function} Buffered handler
128
112
  */
129
- static framebuffer(cb: Function, key: string, order?: number): Function;
113
+ static framebuffer(cb: Function, key: string, priority?: number): Function;
130
114
  /**
131
115
  * Flush buffered frame events
132
116
  *