@homelib/utils 0.0.0-wip.ba4eafa051eb → 0.0.0-wip.c200d1708428
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.
- package/README.md +4 -0
- package/bld/library/debounce.d.ts +1 -0
- package/bld/library/debounce.js +8 -0
- package/bld/library/debounce.js.map +1 -0
- package/bld/library/index.d.ts +2 -0
- package/bld/library/index.js +2 -0
- package/bld/library/index.js.map +1 -1
- package/bld/library/keep-alive.d.ts +6 -0
- package/bld/library/keep-alive.js +18 -0
- package/bld/library/keep-alive.js.map +1 -0
- package/package.json +4 -3
- package/src/library/debounce.ts +11 -0
- package/src/library/index.ts +2 -0
- package/src/library/keep-alive.ts +24 -0
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
[](https://www.npmjs.com/package/@homelib/utils)
|
|
2
|
+
[](../../LICENSE)
|
|
3
|
+
[](https://discord.gg/wEVn2qcf8h)
|
|
4
|
+
|
|
1
5
|
# @homelib/utils
|
|
2
6
|
|
|
3
7
|
Just another awesome magic.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function debounce<T extends (...args: any[]) => void>(fn: T, delay: number): (...args: Parameters<T>) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debounce.js","sourceRoot":"","sources":["../../src/library/debounce.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,QAAQ,CACtB,EAAK,EACL,KAAa;IAEb,IAAI,OAAmC,CAAC;IAExC,OAAO,CAAC,GAAG,IAAmB,EAAE,EAAE;QAChC,YAAY,CAAC,OAAO,CAAC,CAAC;QACtB,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;IACjD,CAAC,CAAC;AACJ,CAAC"}
|
package/bld/library/index.d.ts
CHANGED
package/bld/library/index.js
CHANGED
package/bld/library/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/library/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/library/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a keep-alive tracker for MobX reactions. Call the returned function
|
|
3
|
+
* inside an `autorun`/`reaction` to ensure it re-runs at least once every
|
|
4
|
+
* `interval` milliseconds. Each call resets the timer.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createKeepAlive(interval: number): () => void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { action, observable } from 'mobx';
|
|
2
|
+
import { debounce } from './debounce.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a keep-alive tracker for MobX reactions. Call the returned function
|
|
5
|
+
* inside an `autorun`/`reaction` to ensure it re-runs at least once every
|
|
6
|
+
* `interval` milliseconds. Each call resets the timer.
|
|
7
|
+
*/
|
|
8
|
+
export function createKeepAlive(interval) {
|
|
9
|
+
const keepAlive = observable.box(0);
|
|
10
|
+
const scheduleKeepAlive = debounce(action(() => {
|
|
11
|
+
keepAlive.set(keepAlive.get() + 1);
|
|
12
|
+
}), interval);
|
|
13
|
+
return () => {
|
|
14
|
+
keepAlive.get();
|
|
15
|
+
scheduleKeepAlive();
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=keep-alive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keep-alive.js","sourceRoot":"","sources":["../../src/library/keep-alive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,MAAM,CAAC;AAExC,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AAEvC;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAEpC,MAAM,iBAAiB,GAAG,QAAQ,CAChC,MAAM,CAAC,GAAG,EAAE;QACV,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IACrC,CAAC,CAAC,EACF,QAAQ,CACT,CAAC;IAEF,OAAO,GAAG,EAAE;QACV,SAAS,CAAC,GAAG,EAAE,CAAC;QAChB,iBAAiB,EAAE,CAAC;IACtB,CAAC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@homelib/utils",
|
|
3
|
-
"version": "0.0.0-wip.
|
|
3
|
+
"version": "0.0.0-wip.c200d1708428",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -13,8 +13,9 @@
|
|
|
13
13
|
"default": "./bld/library/index.js"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@homelib/core": "0.0.0-wip.
|
|
16
|
+
"@homelib/core": "0.0.0-wip.c200d1708428",
|
|
17
|
+
"mobx": "^6.16.1",
|
|
17
18
|
"tslib": "^2.8.1"
|
|
18
19
|
},
|
|
19
|
-
"gitHead": "
|
|
20
|
+
"gitHead": "c200d1708428b22bcd86e415abe0ae60e6dbd2ae"
|
|
20
21
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function debounce<T extends (...args: any[]) => void>(
|
|
2
|
+
fn: T,
|
|
3
|
+
delay: number,
|
|
4
|
+
): (...args: Parameters<T>) => void {
|
|
5
|
+
let timeout: NodeJS.Timeout | undefined;
|
|
6
|
+
|
|
7
|
+
return (...args: Parameters<T>) => {
|
|
8
|
+
clearTimeout(timeout);
|
|
9
|
+
timeout = setTimeout(() => fn(...args), delay);
|
|
10
|
+
};
|
|
11
|
+
}
|
package/src/library/index.ts
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {action, observable} from 'mobx';
|
|
2
|
+
|
|
3
|
+
import {debounce} from './debounce.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a keep-alive tracker for MobX reactions. Call the returned function
|
|
7
|
+
* inside an `autorun`/`reaction` to ensure it re-runs at least once every
|
|
8
|
+
* `interval` milliseconds. Each call resets the timer.
|
|
9
|
+
*/
|
|
10
|
+
export function createKeepAlive(interval: number): () => void {
|
|
11
|
+
const keepAlive = observable.box(0);
|
|
12
|
+
|
|
13
|
+
const scheduleKeepAlive = debounce(
|
|
14
|
+
action(() => {
|
|
15
|
+
keepAlive.set(keepAlive.get() + 1);
|
|
16
|
+
}),
|
|
17
|
+
interval,
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
return () => {
|
|
21
|
+
keepAlive.get();
|
|
22
|
+
scheduleKeepAlive();
|
|
23
|
+
};
|
|
24
|
+
}
|