@livelybone/singleton 1.3.5 → 1.3.7
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/index.d.ts +1 -1
- package/lib/es/index.js +4 -3
- package/lib/umd/index.js +3 -3
- package/package.json +3 -2
package/index.d.ts
CHANGED
@@ -38,7 +38,7 @@ declare function singletonObj<T extends any>(id: ID, defaultValue?: () => T): T
|
|
38
38
|
* Return a singleton of an object(such as Promise, Function, Object...) corresponding to the id.
|
39
39
|
* This method will cause OOM if it's used too much without calling `delete`.
|
40
40
|
* */
|
41
|
-
declare function singleton<T extends
|
41
|
+
declare function singleton<T extends any>(
|
42
42
|
id: ID,
|
43
43
|
defaultValue?: () => T,
|
44
44
|
): {
|
package/lib/es/index.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* Bundle of @livelybone/singleton
|
3
|
-
* Generated:
|
4
|
-
* Version: 1.3.
|
3
|
+
* Generated: 2025-04-21
|
4
|
+
* Version: 1.3.7
|
5
5
|
* License: MIT
|
6
6
|
* Author: 2631541504@qq.com
|
7
7
|
*/
|
@@ -53,7 +53,8 @@ function singleton(id, defaultValue) {
|
|
53
53
|
return ids.delete(k);
|
54
54
|
},
|
55
55
|
update: function update(action) {
|
56
|
-
|
56
|
+
// @ts-ignore
|
57
|
+
var v = typeof action === 'function' ? action(ids.get(k)) : action;
|
57
58
|
ids.set(k, v);
|
58
59
|
return v;
|
59
60
|
}
|
package/lib/umd/index.js
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
/**
|
2
2
|
* Bundle of @livelybone/singleton
|
3
|
-
* Generated:
|
4
|
-
* Version: 1.3.
|
3
|
+
* Generated: 2025-04-21
|
4
|
+
* Version: 1.3.7
|
5
5
|
* License: MIT
|
6
6
|
* Author: 2631541504@qq.com
|
7
7
|
*/
|
8
8
|
|
9
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self).Singleton={})}(this,function(e){"use strict";function c(){var e="undefined"!=typeof window?window:global;return e.$$SingletonIdsMap&&e.$$SingletonIdsMap instanceof Map||(e.$$SingletonIdsMap=new Map),e.$$SingletonIdsMap}e.onceRun=function(e,n){var t=c(),n=n?"once-run-".concat(n):e;t.has(n)||t.set(n,e())},e.promiseOnPending=function(e,n){function t(){return i.delete(a)}function o(){return void 0===u?t():setTimeout(t,u),!0}var i=c(),r=n.id,u=n.cacheTime||n.delayTime,a=r?"promise-".concat(r):e;return i.has(a)||i.set(a,e().then(function(e){return o(),e},function(e){return Promise.reject((o(),e))})),i.get(a)},e.runInterval=function(e,n){var t=c(),o="timer-".concat(e||"default"),i=(t.has(o)&&t.get(o)(),n());return t.set(o,function(){clearInterval(i),t.delete(o)}),t.get(o)},e.singleton=function(e,n){var t=c(),o="singleton-any-".concat(e||"default");return t.has(o)||t.set(o,n?n():{}),{value:t.get(o),delete:function(){return t.delete(o)},update:function(e){e="function"==typeof e?e(t.get()):e;return t.set(o,e),e}}},e.singletonObj=function(e,n){var t=c(),e="singleton-any-".concat(e||"default");return t.has(e)||t.set(e,n?n():{}),t.get(e)},Object.defineProperty(e,"__esModule",{value:!0})});
|
9
|
+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self).Singleton={})}(this,function(e){"use strict";function c(){var e="undefined"!=typeof window?window:global;return e.$$SingletonIdsMap&&e.$$SingletonIdsMap instanceof Map||(e.$$SingletonIdsMap=new Map),e.$$SingletonIdsMap}e.onceRun=function(e,n){var t=c(),n=n?"once-run-".concat(n):e;t.has(n)||t.set(n,e())},e.promiseOnPending=function(e,n){function t(){return i.delete(a)}function o(){return void 0===u?t():setTimeout(t,u),!0}var i=c(),r=n.id,u=n.cacheTime||n.delayTime,a=r?"promise-".concat(r):e;return i.has(a)||i.set(a,e().then(function(e){return o(),e},function(e){return Promise.reject((o(),e))})),i.get(a)},e.runInterval=function(e,n){var t=c(),o="timer-".concat(e||"default"),i=(t.has(o)&&t.get(o)(),n());return t.set(o,function(){clearInterval(i),t.delete(o)}),t.get(o)},e.singleton=function(e,n){var t=c(),o="singleton-any-".concat(e||"default");return t.has(o)||t.set(o,n?n():{}),{value:t.get(o),delete:function(){return t.delete(o)},update:function(e){e="function"==typeof e?e(t.get(o)):e;return t.set(o,e),e}}},e.singletonObj=function(e,n){var t=c(),e="singleton-any-".concat(e||"default");return t.has(e)||t.set(e,n?n():{}),t.get(e)},Object.defineProperty(e,"__esModule",{value:!0})});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@livelybone/singleton",
|
3
|
-
"version": "1.3.
|
3
|
+
"version": "1.3.7",
|
4
4
|
"description": "A util of singleton wrapping",
|
5
5
|
"main": "./lib/umd/index.js",
|
6
6
|
"module": "./lib/es/index.js",
|
@@ -41,6 +41,7 @@
|
|
41
41
|
"@babel/preset-env": "^7.5.0",
|
42
42
|
"@babel/preset-typescript": "^7.3.3",
|
43
43
|
"@babel/runtime": "^7.5.1",
|
44
|
+
"@types/node": "^22.14.1",
|
44
45
|
"@typescript-eslint/eslint-plugin": "^1.12.0",
|
45
46
|
"@typescript-eslint/parser": "^1.11.0",
|
46
47
|
"babel-plugin-istanbul": "^5.1.4",
|
@@ -88,4 +89,4 @@
|
|
88
89
|
"git update-index --again"
|
89
90
|
]
|
90
91
|
}
|
91
|
-
}
|
92
|
+
}
|