@jscrpt/common 3.0.0-beta.20220907065830 → 3.0.0
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/changelog.md +2 -2
- package/es/src/decorators/debounceCall.decorator.js.map +1 -1
- package/es/src/decorators/debounceCall.decorator.mjs +0 -2
- package/es/src/decorators/withSync.decorator.js.map +1 -1
- package/es/src/decorators/withSync.decorator.mjs +2 -1
- package/es2015/src/decorators/debounceCall.decorator.js +0 -2
- package/es2015/src/decorators/debounceCall.decorator.js.map +1 -1
- package/es2015/src/decorators/withSync.decorator.js +2 -1
- package/es2015/src/decorators/withSync.decorator.js.map +1 -1
- package/es2020/src/decorators/debounceCall.decorator.js +0 -2
- package/es2020/src/decorators/debounceCall.decorator.js.map +1 -1
- package/es2020/src/decorators/withSync.decorator.js +2 -1
- package/es2020/src/decorators/withSync.decorator.js.map +1 -1
- package/es5/src/decorators/debounceCall.decorator.js +0 -2
- package/es5/src/decorators/debounceCall.decorator.js.map +1 -1
- package/es5/src/decorators/withSync.decorator.js +4 -3
- package/es5/src/decorators/withSync.decorator.js.map +1 -1
- package/module/src/decorators/debounceCall.decorator.cjs +0 -2
- package/module/src/decorators/debounceCall.decorator.js.map +1 -1
- package/module/src/decorators/withSync.decorator.cjs +2 -1
- package/module/src/decorators/withSync.decorator.js.map +1 -1
- package/package.json +1 -1
- package/src/decorators/debounceCall.decorator.d.ts.map +1 -1
- package/src/decorators/withSync.decorator.d.ts.map +1 -1
- package/version.bak +1 -1
package/changelog.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## Version 3.0.0 (2022-09-
|
|
3
|
+
## Version 3.0.0 (2022-09-07)
|
|
4
4
|
|
|
5
5
|
### Bug Fixes
|
|
6
6
|
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
- **methods**
|
|
26
26
|
- `invalidateVisuals` - explicitly runs invalidation of content (change detection), which redraws contents
|
|
27
27
|
- new `WithSync` decorator, that adds special functionality to async method call, that allows only to call this method only when previous execution was finished
|
|
28
|
-
- updated `DebounceCall`, now asynchronously returns values,
|
|
28
|
+
- updated `DebounceCall`, now asynchronously returns values, all calls returns value from last call
|
|
29
29
|
|
|
30
30
|
### BREAKING CHANGES
|
|
31
31
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debounceCall.decorator.mjs","sourceRoot":"","sources":["../../../src/decorators/debounceCall.decorator.ts"],"names":[],"mappings":";AAEA,OAAO,EAAC,UAAU,EAAE,SAAS,EAAC,MAAM,eAAe,CAAC;AAEpD;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa;IAEtC,OAAO,UAAS,OAAe,EAAE,WAA0B,EAAE,UAA8B;;QAEvF,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;QACnC,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;QACnC,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;QACjC,MAAM,aAAa,GAAc,MAAA,UAAU,CAAC,KAAK,mCAAI,MAAA,UAAU,CAAC,GAAG,0DAAI,CAAC;QAExE,IAAG,CAAC,UAAU,CAAC,aAAa,CAAC,EAC7B;YACI,MAAM,IAAI,KAAK,CAAC,iDAAiD,WAAW,CAAC,QAAQ,EAAE,wBAAwB,CAAC,CAAC;SACpH;QAED,UAAU,CAAC,KAAK,GAAG,UAA+H,GAAG,IAAe;YAEhK,iCAAiC;YACjC,IAAG,CAAC,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,IAAI,IAAI,CAAC,EAC1C;gBACI,IAAI,SAA+C,CAAC;gBACpD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAoB,OAAO,CAAC,EAAE,CAAC,SAAS,GAAG,OAAO,CAAC,CAAC;gBAE/E,OAAO,CAAC,cAAc,CAAC,IAAI,EACJ,OAAO,EACP;oBACI,Q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AAO,CAAC,CAAC;gBAE/E,OAAO,CAAC,cAAc,CAAC,IAAI,EACJ,OAAO,EACP;oBACI,QAAQ,EAAE,IAAI;oBACd,KAAK,EAAE,SAAS;iBACnB,CAAC,CAAC;gBAE1B,OAAO,CAAC,cAAc,CAAC,IAAI,EACJ,MAAM,EACN;oBACI,QAAQ,EAAE,IAAI;oBACd,KAAK,EAAE,OAAO;iBACjB,CAAC,CAAC;aAC7B;YAID,IAAG,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,EAC3B;gBACI,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;aAC/B;YAED,kCAAkC;YAClC,IAAG,CAAC,CAAC,OAAO,IAAI,IAAI,CAAC,EACrB;gBACI,OAAO,CAAC,cAAc,CAAC,IAAI,EACJ,OAAO,EACP;oBACI,QAAQ,EAAE,IAAI;oBACd,KAAK,EAAE,IAAI;iBACd,CAAC,CAAC;aAC7B;YAED,IAAI,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC,GAAS,EAAE;gBAElC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,aAAa,CAAC,KAAK,CAAiC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;gBACrF,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,OAAO,CAAoB,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC;gBACtF,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;YACzB,CAAC,CAAA,EAAE,KAAK,CAAQ,CAAC;YAEjB,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;QACxB,CAAC,CAAC;QAEF,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;AACN,CAAC","sourcesContent":["import {PromiseOr} from '../types/async';\r\nimport {Action1, Func} from '../types/functions';\r\nimport {isFunction, isPresent} from '../utils/lang';\r\n\r\n/**\r\n * Adds special functionality to method call, that debounce method call for specified time\r\n * @param delay - Number of miliseconds that delays function call\r\n */\r\nexport function DebounceCall(delay: number): MethodDecorator\r\n{\r\n return function(_target: Object, propertyKey: string|symbol, descriptor: PropertyDescriptor)\r\n {\r\n const timeout = Symbol('ɵTimeout');\r\n const resolve = Symbol('ɵResolve');\r\n const result = Symbol('ɵResult');\r\n const originalValue: Func<any> = descriptor.value ?? descriptor.get?.();\r\n\r\n if(!isFunction(originalValue))\r\n {\r\n throw new Error(`Unable to apply @DebounceCall() decorator to '${propertyKey.toString()}', it is not a method.`);\r\n }\r\n\r\n descriptor.value = function<TResult>(this: {[timeout]: number|null, [resolve]: Action1<TResult|undefined>, [result]: Promise<TResult|undefined>}, ...args: unknown[]): Promise<TResult|undefined>\r\n {\r\n //result variable does not exists\r\n if(!(resolve in this) && !(result in this))\r\n {\r\n let resolveFn: Action1<TResult|undefined>|undefined;\r\n const promise = new Promise<TResult|undefined>(resolve => resolveFn = resolve);\r\n\r\n Reflect.defineProperty(this,\r\n resolve,\r\n {\r\n writable: true,\r\n value: resolveFn,\r\n });\r\n\r\n Reflect.defineProperty(this,\r\n result,\r\n {\r\n writable: true,\r\n value: promise,\r\n });\r\n }\r\n\r\n \r\n\r\n if(isPresent(this[timeout]))\r\n {\r\n clearTimeout(this[timeout]);\r\n }\r\n\r\n //timeout variable does not exists\r\n if(!(timeout in this))\r\n {\r\n Reflect.defineProperty(this,\r\n timeout,\r\n {\r\n writable: true,\r\n value: null,\r\n });\r\n }\r\n\r\n this[timeout] = setTimeout(async () =>\r\n {\r\n this[resolve](await originalValue.apply<any, any[], PromiseOr<TResult>>(this, args));\r\n this[result] = new Promise<TResult|undefined>(resolveFn => this[resolve] = resolveFn);\r\n this[timeout] = null;\r\n }, delay) as any;\r\n\r\n return this[result];\r\n };\r\n\r\n return descriptor;\r\n };\r\n}"]}
|
|
@@ -30,8 +30,6 @@ export function DebounceCall(delay) {
|
|
|
30
30
|
}
|
|
31
31
|
if (isPresent(this[timeout])) {
|
|
32
32
|
clearTimeout(this[timeout]);
|
|
33
|
-
this[resolve](undefined);
|
|
34
|
-
this[result] = new Promise(resolveFn => this[resolve] = resolveFn);
|
|
35
33
|
}
|
|
36
34
|
//timeout variable does not exists
|
|
37
35
|
if (!(timeout in this)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withSync.decorator.mjs","sourceRoot":"","sources":["../../../src/decorators/withSync.decorator.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAEzC;;GAEG;AACH,MAAM,UAAU,QAAQ;IAEpB,OAAO,UAAS,OAAe,EAAE,WAA0B,EAAE,UAA8B;;QAEvF,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;QAC7B,MAAM,aAAa,GAAc,MAAA,UAAU,CAAC,KAAK,mCAAI,MAAA,UAAU,CAAC,GAAG,0DAAI,CAAC;QAExE,IAAG,CAAC,UAAU,CAAC,aAAa,CAAC,EAC7B;YACI,MAAM,IAAI,KAAK,CAAC,6CAA6C,WAAW,CAAC,QAAQ,EAAE,wBAAwB,CAAC,CAAC;SAChH;QAED,UAAU,CAAC,KAAK,GAAG,UAA8D,GAAG,IAAe;;gBAE/F,+BAA+B;gBAC/B,IAAG,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,EAClB;oBACI,OAAO,CAAC,cAAc,CAAC,IAAI,EACJ,IAAI,EACJ;wBACI,QAAQ,EAAE,IAAI;wBACd,KAAK,EAAE,OAAO,CAAC,OAAO,EAAE;qBAC3B,CAAC,CAAC;iBAC7B;gBAED,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"withSync.decorator.mjs","sourceRoot":"","sources":["../../../src/decorators/withSync.decorator.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAEzC;;GAEG;AACH,MAAM,UAAU,QAAQ;IAEpB,OAAO,UAAS,OAAe,EAAE,WAA0B,EAAE,UAA8B;;QAEvF,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;QAC7B,MAAM,aAAa,GAAc,MAAA,UAAU,CAAC,KAAK,mCAAI,MAAA,UAAU,CAAC,GAAG,0DAAI,CAAC;QAExE,IAAG,CAAC,UAAU,CAAC,aAAa,CAAC,EAC7B;YACI,MAAM,IAAI,KAAK,CAAC,6CAA6C,WAAW,CAAC,QAAQ,EAAE,wBAAwB,CAAC,CAAC;SAChH;QAED,UAAU,CAAC,KAAK,GAAG,UAA8D,GAAG,IAAe;;gBAE/F,+BAA+B;gBAC/B,IAAG,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,EAClB;oBACI,OAAO,CAAC,cAAc,CAAC,IAAI,EACJ,IAAI,EACJ;wBACI,QAAQ,EAAE,IAAI;wBACd,KAAK,EAAE,OAAO,CAAC,OAAO,EAAE;qBAC3B,CAAC,CAAC;iBAC7B;gBAED,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC/B,IAAI,WAAiC,CAAC;gBACtC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,WAAW,GAAG,OAAO,CAAC,CAAC;gBAC3D,MAAM,WAAW,CAAC;gBAElB,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,KAAK,CAAsB,IAAI,EAAE,IAAI,CAAC,CAAC;gBAE1E,WAAW,aAAX,WAAW,uBAAX,WAAW,EAAI,CAAC;gBAEhB,OAAO,MAAM,CAAC;YAClB,CAAC;SAAA,CAAC;QAEF,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;AACN,CAAC","sourcesContent":["import {Func, NoopAction} from '../types/functions';\nimport {isFunction} from '../utils/lang';\n\n/**\n * Adds special functionality to async method call, that allows only to call this method only when previous execution was finished\n */\nexport function WithSync(): MethodDecorator\n{\n return function(_target: Object, propertyKey: string|symbol, descriptor: PropertyDescriptor)\n {\n const sync = Symbol('ɵSync');\n const originalValue: Func<any> = descriptor.value ?? descriptor.get?.();\n\n if(!isFunction(originalValue))\n {\n throw new Error(`Unable to apply @WithSync() decorator to '${propertyKey.toString()}', it is not a method.`);\n }\n\n descriptor.value = async function<TResult>(this: {[key: symbol]: Promise<void>}, ...args: unknown[]): Promise<TResult>\n {\n //sync variable does not exists\n if(!(sync in this))\n {\n Reflect.defineProperty(this,\n sync,\n {\n writable: true,\n value: Promise.resolve(),\n });\n }\n\n const syncPromise = this[sync];\n let syncResolve: NoopAction|undefined;\n this[sync] = new Promise(resolve => syncResolve = resolve);\n await syncPromise;\n\n const result = await originalValue.apply<any, any[], TResult>(this, args);\n\n syncResolve?.();\n\n return result;\n };\n\n return descriptor;\n };\n}"]}
|
|
@@ -20,9 +20,10 @@ export function WithSync() {
|
|
|
20
20
|
value: Promise.resolve(),
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
const syncPromise = this[sync];
|
|
24
24
|
let syncResolve;
|
|
25
25
|
this[sync] = new Promise(resolve => syncResolve = resolve);
|
|
26
|
+
yield syncPromise;
|
|
26
27
|
const result = yield originalValue.apply(this, args);
|
|
27
28
|
syncResolve === null || syncResolve === void 0 ? void 0 : syncResolve();
|
|
28
29
|
return result;
|
|
@@ -30,8 +30,6 @@ export function DebounceCall(delay) {
|
|
|
30
30
|
}
|
|
31
31
|
if (isPresent(this[timeout])) {
|
|
32
32
|
clearTimeout(this[timeout]);
|
|
33
|
-
this[resolve](undefined);
|
|
34
|
-
this[result] = new Promise(resolveFn => this[resolve] = resolveFn);
|
|
35
33
|
}
|
|
36
34
|
//timeout variable does not exists
|
|
37
35
|
if (!(timeout in this)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debounceCall.decorator.js","sourceRoot":"","sources":["../../../src/decorators/debounceCall.decorator.ts"],"names":[],"mappings":";AAEA,OAAO,EAAC,UAAU,EAAE,SAAS,EAAC,MAAM,eAAe,CAAC;AAEpD;;;GAGG;AACH,MAAM,UAAU,YAA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CAAC,OAAO,IAAI,IAAI,CAAC,EACrB;gBACI,OAAO,CAAC,cAAc,CAAC,IAAI,EACJ,OAAO,EACP;oBACI,QAAQ,EAAE,IAAI;oBACd,KAAK,EAAE,IAAI;iBACd,CAAC,CAAC;aAC7B;YAED,IAAI,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC,GAAS,EAAE;gBAElC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,aAAa,CAAC,KAAK,CAAiC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;gBACrF,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,OAAO,CAAoB,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC;gBACtF,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;YACzB,CAAC,CAAA,EAAE,KAAK,CAAQ,CAAC;YAEjB,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;QACxB,CAAC,CAAC;QAEF,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;AACN,CAAC","sourcesContent":["import {PromiseOr} from '../types/async';\r\nimport {Action1, Func} from '../types/functions';\r\nimport {isFunction, isPresent} from '../utils/lang';\r\n\r\n/**\r\n * Adds special functionality to method call, that debounce method call for specified time\r\n * @param delay - Number of miliseconds that delays function call\r\n */\r\nexport function DebounceCall(delay: number): MethodDecorator\r\n{\r\n return function(_target: Object, propertyKey: string|symbol, descriptor: PropertyDescriptor)\r\n {\r\n const timeout = Symbol('ɵTimeout');\r\n const resolve = Symbol('ɵResolve');\r\n const result = Symbol('ɵResult');\r\n const originalValue: Func<any> = descriptor.value ?? descriptor.get?.();\r\n\r\n if(!isFunction(originalValue))\r\n {\r\n throw new Error(`Unable to apply @DebounceCall() decorator to '${propertyKey.toString()}', it is not a method.`);\r\n }\r\n\r\n descriptor.value = function<TResult>(this: {[timeout]: number|null, [resolve]: Action1<TResult|undefined>, [result]: Promise<TResult|undefined>}, ...args: unknown[]): Promise<TResult|undefined>\r\n {\r\n //result variable does not exists\r\n if(!(resolve in this) && !(result in this))\r\n {\r\n let resolveFn: Action1<TResult|undefined>|undefined;\r\n const promise = new Promise<TResult|undefined>(resolve => resolveFn = resolve);\r\n\r\n Reflect.defineProperty(this,\r\n resolve,\r\n {\r\n writable: true,\r\n value: resolveFn,\r\n });\r\n\r\n Reflect.defineProperty(this,\r\n result,\r\n {\r\n writable: true,\r\n value: promise,\r\n });\r\n }\r\n\r\n \r\n\r\n if(isPresent(this[timeout]))\r\n {\r\n clearTimeout(this[timeout]);\r\n }\r\n\r\n //timeout variable does not exists\r\n if(!(timeout in this))\r\n {\r\n Reflect.defineProperty(this,\r\n timeout,\r\n {\r\n writable: true,\r\n value: null,\r\n });\r\n }\r\n\r\n this[timeout] = setTimeout(async () =>\r\n {\r\n this[resolve](await originalValue.apply<any, any[], PromiseOr<TResult>>(this, args));\r\n this[result] = new Promise<TResult|undefined>(resolveFn => this[resolve] = resolveFn);\r\n this[timeout] = null;\r\n }, delay) as any;\r\n\r\n return this[result];\r\n };\r\n\r\n return descriptor;\r\n };\r\n}"]}
|
|
@@ -20,9 +20,10 @@ export function WithSync() {
|
|
|
20
20
|
value: Promise.resolve(),
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
const syncPromise = this[sync];
|
|
24
24
|
let syncResolve;
|
|
25
25
|
this[sync] = new Promise(resolve => syncResolve = resolve);
|
|
26
|
+
yield syncPromise;
|
|
26
27
|
const result = yield originalValue.apply(this, args);
|
|
27
28
|
syncResolve === null || syncResolve === void 0 ? void 0 : syncResolve();
|
|
28
29
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withSync.decorator.js","sourceRoot":"","sources":["../../../src/decorators/withSync.decorator.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAEzC;;GAEG;AACH,MAAM,UAAU,QAAQ;IAEpB,OAAO,UAAS,OAAe,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C,CAAC,IAAI,IAAI,IAAI,CAAC,EAClB;oBACI,OAAO,CAAC,cAAc,CAAC,IAAI,EACJ,IAAI,EACJ;wBACI,QAAQ,EAAE,IAAI;wBACd,KAAK,EAAE,OAAO,CAAC,OAAO,EAAE;qBAC3B,CAAC,CAAC;iBAC7B;gBAED,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC/B,IAAI,WAAiC,CAAC;gBACtC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,WAAW,GAAG,OAAO,CAAC,CAAC;gBAC3D,MAAM,WAAW,CAAC;gBAElB,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,KAAK,CAAsB,IAAI,EAAE,IAAI,CAAC,CAAC;gBAE1E,WAAW,aAAX,WAAW,uBAAX,WAAW,EAAI,CAAC;gBAEhB,OAAO,MAAM,CAAC;YAClB,CAAC;SAAA,CAAC;QAEF,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;AACN,CAAC","sourcesContent":["import {Func, NoopAction} from '../types/functions';\nimport {isFunction} from '../utils/lang';\n\n/**\n * Adds special functionality to async method call, that allows only to call this method only when previous execution was finished\n */\nexport function WithSync(): MethodDecorator\n{\n return function(_target: Object, propertyKey: string|symbol, descriptor: PropertyDescriptor)\n {\n const sync = Symbol('ɵSync');\n const originalValue: Func<any> = descriptor.value ?? descriptor.get?.();\n\n if(!isFunction(originalValue))\n {\n throw new Error(`Unable to apply @WithSync() decorator to '${propertyKey.toString()}', it is not a method.`);\n }\n\n descriptor.value = async function<TResult>(this: {[key: symbol]: Promise<void>}, ...args: unknown[]): Promise<TResult>\n {\n //sync variable does not exists\n if(!(sync in this))\n {\n Reflect.defineProperty(this,\n sync,\n {\n writable: true,\n value: Promise.resolve(),\n });\n }\n\n const syncPromise = this[sync];\n let syncResolve: NoopAction|undefined;\n this[sync] = new Promise(resolve => syncResolve = resolve);\n await syncPromise;\n\n const result = await originalValue.apply<any, any[], TResult>(this, args);\n\n syncResolve?.();\n\n return result;\n };\n\n return descriptor;\n };\n}"]}
|
|
@@ -28,8 +28,6 @@ export function DebounceCall(delay) {
|
|
|
28
28
|
}
|
|
29
29
|
if (isPresent(this[timeout])) {
|
|
30
30
|
clearTimeout(this[timeout]);
|
|
31
|
-
this[resolve](undefined);
|
|
32
|
-
this[result] = new Promise(resolveFn => this[resolve] = resolveFn);
|
|
33
31
|
}
|
|
34
32
|
//timeout variable does not exists
|
|
35
33
|
if (!(timeout in this)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debounceCall.decorator.js","sourceRoot":"","sources":["../../../src/decorators/debounceCall.decorator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,UAAU,EAAE,SAAS,EAAC,MAAM,eAAe,CAAC;AAEpD;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa;IAEtC,OAAO,UAAS,OAAe,EAAE,WAA0B,EAAE,UAA8B;QAEvF,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;QACnC,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;QACnC,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;QACjC,MAAM,aAAa,GAAc,UAAU,CAAC,KAAK,IAAI,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC;QAExE,IAAG,CAAC,UAAU,CAAC,aAAa,CAAC,EAC7B;YACI,MAAM,IAAI,KAAK,CAAC,iDAAiD,WAAW,CAAC,QAAQ,EAAE,wBAAwB,CAAC,CAAC;SACpH;QAED,UAAU,CAAC,KAAK,GAAG,UAA+H,GAAG,IAAe;YAEhK,iCAAiC;YACjC,IAAG,CAAC,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,IAAI,IAAI,CAAC,EAC1C;gBACI,IAAI,SAA+C,CAAC;gBACpD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAoB,OAAO,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from '../types/functions';\r\nimport {isFunction, isPresent} from '../utils/lang';\r\n\r\n/**\r\n * Adds special functionality to method call, that debounce method call for specified time\r\n * @param delay - Number of miliseconds that delays function call\r\n */\r\nexport function DebounceCall(delay: number): MethodDecorator\r\n{\r\n return function(_target: Object, propertyKey: string|symbol, descriptor: PropertyDescriptor)\r\n {\r\n const timeout = Symbol('ɵTimeout');\r\n const resolve = Symbol('ɵResolve');\r\n const result = Symbol('ɵResult');\r\n const originalValue: Func<any> = descriptor.value ?? descriptor.get?.();\r\n\r\n if(!isFunction(originalValue))\r\n {\r\n throw new Error(`Unable to apply @DebounceCall() decorator to '${propertyKey.toString()}', it is not a method.`);\r\n }\r\n\r\n descriptor.value = function<TResult>(this: {[timeout]: number|null, [resolve]: Action1<TResult|undefined>, [result]: Promise<TResult|undefined>}, ...args: unknown[]): Promise<TResult|undefined>\r\n {\r\n //result variable does not exists\r\n if(!(resolve in this) && !(result in this))\r\n {\r\n let resolveFn: Action1<TResult|undefined>|undefined;\r\n const promise = new Promise<TResult|undefined>(resolve => resolveFn = resolve);\r\n\r\n Reflect.defineProperty(this,\r\n resolve,\r\n {\r\n writable: true,\r\n value: resolveFn,\r\n });\r\n\r\n Reflect.defineProperty(this,\r\n result,\r\n {\r\n writable: true,\r\n value: promise,\r\n });\r\n }\r\n\r\n \r\n\r\n if(isPresent(this[timeout]))\r\n {\r\n clearTimeout(this[timeout]);\r\n }\r\n\r\n //timeout variable does not exists\r\n if(!(timeout in this))\r\n {\r\n Reflect.defineProperty(this,\r\n timeout,\r\n {\r\n writable: true,\r\n value: null,\r\n });\r\n }\r\n\r\n this[timeout] = setTimeout(async () =>\r\n {\r\n this[resolve](await originalValue.apply<any, any[], PromiseOr<TResult>>(this, args));\r\n this[result] = new Promise<TResult|undefined>(resolveFn => this[resolve] = resolveFn);\r\n this[timeout] = null;\r\n }, delay) as any;\r\n\r\n return this[result];\r\n };\r\n\r\n return descriptor;\r\n };\r\n}"]}
|
|
@@ -17,9 +17,10 @@ export function WithSync() {
|
|
|
17
17
|
value: Promise.resolve(),
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
const syncPromise = this[sync];
|
|
21
21
|
let syncResolve;
|
|
22
22
|
this[sync] = new Promise(resolve => syncResolve = resolve);
|
|
23
|
+
await syncPromise;
|
|
23
24
|
const result = await originalValue.apply(this, args);
|
|
24
25
|
syncResolve?.();
|
|
25
26
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withSync.decorator.js","sourceRoot":"","sources":["../../../src/decorators/withSync.decorator.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAEzC;;GAEG;AACH,MAAM,UAAU,QAAQ;IAEpB,OAAO,UAAS,OAAe,EAAE,WAA0B,EAAE,UAA8B;QAEvF,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;QAC7B,MAAM,aAAa,GAAc,UAAU,CAAC,KAAK,IAAI,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC;QAExE,IAAG,CAAC,UAAU,CAAC,aAAa,CAAC,EAC7B;YACI,MAAM,IAAI,KAAK,CAAC,6CAA6C,WAAW,CAAC,QAAQ,EAAE,wBAAwB,CAAC,CAAC;SAChH;QAED,UAAU,CAAC,KAAK,GAAG,KAAK,WAAyD,GAAG,IAAe;YAE/F,+BAA+B;YAC/B,IAAG,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,EAClB;gBACI,OAAO,CAAC,cAAc,CAAC,IAAI,EACJ,IAAI,EACJ;oBACI,QAAQ,EAAE,IAAI;oBACd,KAAK,EAAE,OAAO,CAAC,OAAO,EAAE;iBAC3B,CAAC,CAAC;aAC7B;YAED,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"withSync.decorator.js","sourceRoot":"","sources":["../../../src/decorators/withSync.decorator.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAEzC;;GAEG;AACH,MAAM,UAAU,QAAQ;IAEpB,OAAO,UAAS,OAAe,EAAE,WAA0B,EAAE,UAA8B;QAEvF,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;QAC7B,MAAM,aAAa,GAAc,UAAU,CAAC,KAAK,IAAI,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC;QAExE,IAAG,CAAC,UAAU,CAAC,aAAa,CAAC,EAC7B;YACI,MAAM,IAAI,KAAK,CAAC,6CAA6C,WAAW,CAAC,QAAQ,EAAE,wBAAwB,CAAC,CAAC;SAChH;QAED,UAAU,CAAC,KAAK,GAAG,KAAK,WAAyD,GAAG,IAAe;YAE/F,+BAA+B;YAC/B,IAAG,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,EAClB;gBACI,OAAO,CAAC,cAAc,CAAC,IAAI,EACJ,IAAI,EACJ;oBACI,QAAQ,EAAE,IAAI;oBACd,KAAK,EAAE,OAAO,CAAC,OAAO,EAAE;iBAC3B,CAAC,CAAC;aAC7B;YAED,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;YAC/B,IAAI,WAAiC,CAAC;YACtC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,WAAW,GAAG,OAAO,CAAC,CAAC;YAC3D,MAAM,WAAW,CAAC;YAElB,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,KAAK,CAAsB,IAAI,EAAE,IAAI,CAAC,CAAC;YAE1E,WAAW,EAAE,EAAE,CAAC;YAEhB,OAAO,MAAM,CAAC;QAClB,CAAC,CAAC;QAEF,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;AACN,CAAC","sourcesContent":["import {Func, NoopAction} from '../types/functions';\nimport {isFunction} from '../utils/lang';\n\n/**\n * Adds special functionality to async method call, that allows only to call this method only when previous execution was finished\n */\nexport function WithSync(): MethodDecorator\n{\n return function(_target: Object, propertyKey: string|symbol, descriptor: PropertyDescriptor)\n {\n const sync = Symbol('ɵSync');\n const originalValue: Func<any> = descriptor.value ?? descriptor.get?.();\n\n if(!isFunction(originalValue))\n {\n throw new Error(`Unable to apply @WithSync() decorator to '${propertyKey.toString()}', it is not a method.`);\n }\n\n descriptor.value = async function<TResult>(this: {[key: symbol]: Promise<void>}, ...args: unknown[]): Promise<TResult>\n {\n //sync variable does not exists\n if(!(sync in this))\n {\n Reflect.defineProperty(this,\n sync,\n {\n writable: true,\n value: Promise.resolve(),\n });\n }\n\n const syncPromise = this[sync];\n let syncResolve: NoopAction|undefined;\n this[sync] = new Promise(resolve => syncResolve = resolve);\n await syncPromise;\n\n const result = await originalValue.apply<any, any[], TResult>(this, args);\n\n syncResolve?.();\n\n return result;\n };\n\n return descriptor;\n };\n}"]}
|
|
@@ -35,8 +35,6 @@ export function DebounceCall(delay) {
|
|
|
35
35
|
}
|
|
36
36
|
if (isPresent(this[timeout])) {
|
|
37
37
|
clearTimeout(this[timeout]);
|
|
38
|
-
this[resolve](undefined);
|
|
39
|
-
this[result] = new Promise(function (resolveFn) { return _this[resolve] = resolveFn; });
|
|
40
38
|
}
|
|
41
39
|
//timeout variable does not exists
|
|
42
40
|
if (!(timeout in this)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debounceCall.decorator.js","sourceRoot":"","sources":["../../../src/decorators/debounceCall.decorator.ts"],"names":[],"mappings":";AAEA,OAAO,EAAC,UAAU,EAAE,SAAS,EAAC,MAAM,eAAe,CAAC;AAEpD;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa;IAEtC,OAAO,UAAS,OAAe,EAAE,WAA0B,EAAE,UAA8B;;QAEvF,IAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;QACnC,IAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;QACnC,IAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;QACjC,IAA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../types/functions';\r\nimport {isFunction, isPresent} from '../utils/lang';\r\n\r\n/**\r\n * Adds special functionality to method call, that debounce method call for specified time\r\n * @param delay - Number of miliseconds that delays function call\r\n */\r\nexport function DebounceCall(delay: number): MethodDecorator\r\n{\r\n return function(_target: Object, propertyKey: string|symbol, descriptor: PropertyDescriptor)\r\n {\r\n const timeout = Symbol('ɵTimeout');\r\n const resolve = Symbol('ɵResolve');\r\n const result = Symbol('ɵResult');\r\n const originalValue: Func<any> = descriptor.value ?? descriptor.get?.();\r\n\r\n if(!isFunction(originalValue))\r\n {\r\n throw new Error(`Unable to apply @DebounceCall() decorator to '${propertyKey.toString()}', it is not a method.`);\r\n }\r\n\r\n descriptor.value = function<TResult>(this: {[timeout]: number|null, [resolve]: Action1<TResult|undefined>, [result]: Promise<TResult|undefined>}, ...args: unknown[]): Promise<TResult|undefined>\r\n {\r\n //result variable does not exists\r\n if(!(resolve in this) && !(result in this))\r\n {\r\n let resolveFn: Action1<TResult|undefined>|undefined;\r\n const promise = new Promise<TResult|undefined>(resolve => resolveFn = resolve);\r\n\r\n Reflect.defineProperty(this,\r\n resolve,\r\n {\r\n writable: true,\r\n value: resolveFn,\r\n });\r\n\r\n Reflect.defineProperty(this,\r\n result,\r\n {\r\n writable: true,\r\n value: promise,\r\n });\r\n }\r\n\r\n \r\n\r\n if(isPresent(this[timeout]))\r\n {\r\n clearTimeout(this[timeout]);\r\n }\r\n\r\n //timeout variable does not exists\r\n if(!(timeout in this))\r\n {\r\n Reflect.defineProperty(this,\r\n timeout,\r\n {\r\n writable: true,\r\n value: null,\r\n });\r\n }\r\n\r\n this[timeout] = setTimeout(async () =>\r\n {\r\n this[resolve](await originalValue.apply<any, any[], PromiseOr<TResult>>(this, args));\r\n this[result] = new Promise<TResult|undefined>(resolveFn => this[resolve] = resolveFn);\r\n this[timeout] = null;\r\n }, delay) as any;\r\n\r\n return this[result];\r\n };\r\n\r\n return descriptor;\r\n };\r\n}"]}
|
|
@@ -17,7 +17,7 @@ export function WithSync() {
|
|
|
17
17
|
args[_i] = arguments[_i];
|
|
18
18
|
}
|
|
19
19
|
return __awaiter(this, void 0, void 0, function () {
|
|
20
|
-
var syncResolve, result;
|
|
20
|
+
var syncPromise, syncResolve, result;
|
|
21
21
|
return __generator(this, function (_a) {
|
|
22
22
|
switch (_a.label) {
|
|
23
23
|
case 0:
|
|
@@ -28,10 +28,11 @@ export function WithSync() {
|
|
|
28
28
|
value: Promise.resolve(),
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
syncPromise = this[sync];
|
|
32
|
+
this[sync] = new Promise(function (resolve) { return syncResolve = resolve; });
|
|
33
|
+
return [4 /*yield*/, syncPromise];
|
|
32
34
|
case 1:
|
|
33
35
|
_a.sent();
|
|
34
|
-
this[sync] = new Promise(function (resolve) { return syncResolve = resolve; });
|
|
35
36
|
return [4 /*yield*/, originalValue.apply(this, args)];
|
|
36
37
|
case 2:
|
|
37
38
|
result = _a.sent();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withSync.decorator.js","sourceRoot":"","sources":["../../../src/decorators/withSync.decorator.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAEzC;;GAEG;AACH,MAAM,UAAU,QAAQ;IAEpB,OAAO,UAAS,OAAe,EAAE,WAA0B,EAAE,UAA8B;;QAEvF,IAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;QAC7B,IAAM,aAAa,GAAc,MAAA,UAAU,CAAC,KAAK,mCAAI,MAAA,UAAU,CAAC,GAAG,0DAAI,CAAC;QAExE,IAAG,CAAC,UAAU,CAAC,aAAa,CAAC,EAC7B;YACI,MAAM,IAAI,KAAK,CAAC,oDAA6C,WAAW,CAAC,QAAQ,EAAE,2BAAwB,CAAC,CAAC;SAChH;QAED,UAAU,CAAC,KAAK,GAAG;YAA8D,cAAkB;iBAAlB,UAAkB,EAAlB,qBAAkB,EAAlB,IAAkB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,WAAW,GAAG,OAAO,EAArB,CAAqB,CAAC,CAAC;4BAC3D,qBAAM,WAAW,EAAA;;4BAAjB,SAAiB,CAAC;4BAEH,qBAAM,aAAa,CAAC,KAAK,CAAsB,IAAI,EAAE,IAAI,CAAC,EAAA;;4BAAnE,MAAM,GAAG,SAA0D;4BAEzE,WAAW,aAAX,WAAW,uBAAX,WAAW,EAAI,CAAC;4BAEhB,sBAAO,MAAM,EAAC;;;;SACjB,CAAC;QAEF,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;AACN,CAAC","sourcesContent":["import {Func, NoopAction} from '../types/functions';\nimport {isFunction} from '../utils/lang';\n\n/**\n * Adds special functionality to async method call, that allows only to call this method only when previous execution was finished\n */\nexport function WithSync(): MethodDecorator\n{\n return function(_target: Object, propertyKey: string|symbol, descriptor: PropertyDescriptor)\n {\n const sync = Symbol('ɵSync');\n const originalValue: Func<any> = descriptor.value ?? descriptor.get?.();\n\n if(!isFunction(originalValue))\n {\n throw new Error(`Unable to apply @WithSync() decorator to '${propertyKey.toString()}', it is not a method.`);\n }\n\n descriptor.value = async function<TResult>(this: {[key: symbol]: Promise<void>}, ...args: unknown[]): Promise<TResult>\n {\n //sync variable does not exists\n if(!(sync in this))\n {\n Reflect.defineProperty(this,\n sync,\n {\n writable: true,\n value: Promise.resolve(),\n });\n }\n\n const syncPromise = this[sync];\n let syncResolve: NoopAction|undefined;\n this[sync] = new Promise(resolve => syncResolve = resolve);\n await syncPromise;\n\n const result = await originalValue.apply<any, any[], TResult>(this, args);\n\n syncResolve?.();\n\n return result;\n };\n\n return descriptor;\n };\n}"]}
|
|
@@ -33,8 +33,6 @@ function DebounceCall(delay) {
|
|
|
33
33
|
}
|
|
34
34
|
if ((0, lang_1.isPresent)(this[timeout])) {
|
|
35
35
|
clearTimeout(this[timeout]);
|
|
36
|
-
this[resolve](undefined);
|
|
37
|
-
this[result] = new Promise(resolveFn => this[resolve] = resolveFn);
|
|
38
36
|
}
|
|
39
37
|
//timeout variable does not exists
|
|
40
38
|
if (!(timeout in this)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debounceCall.decorator.cjs","sourceRoot":"","sources":["../../../src/decorators/debounceCall.decorator.ts"],"names":[],"mappings":";;;;AAEA,wCAAoD;AAEpD;;;GAGG;AACH,SAAgB,YAAY,CAAC,KAAa;IAEtC,OAAO,UAAS,OAAe,EAAE,WAA0B,EAAE,UAA8B;;QAEvF,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;QACnC,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;QACnC,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;QACjC,MAAM,aAAa,GAAc,MAAA,UAAU,CAAC,KAAK,mCAAI,MAAA,UAAU,CAAC,GAAG,0DAAI,CAAC;QAExE,IAAG,CAAC,IAAA,iBAAU,EAAC,aAAa,CAAC,EAC7B;YACI,MAAM,IAAI,KAAK,CAAC,iDAAiD,WAAW,CAAC,QAAQ,EAAE,wBAAwB,CAAC,CAAC;SACpH;QAED,UAAU,CAAC,KAAK,GAAG,UAA+H,GAAG,IAAe;YAEhK,iCAAiC;YACjC,IAAG,CAAC,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,IAAI,IAAI,CAAC,EAC1C;gBACI,IAAI,SAA+C,CAAC;gBACpD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAoB,OAAO,CAAC,EAAE,CAAC,SAAS,GAAG,OAAO,CAAC,CAAC;gBAE/E,OAAO,CAAC,cAAc,CAAC,IAAI,EACJ,OAAO,EACP;oBACI,QAAQ,EAAE,IAAI;oBACd,KAAK,EAAE,SAAS;iBACnB,CAAC,CAAC;gBAE1B,OAAO,CAAC,cAAc,CAAC,IAAI,EACJ,MAAM,EACN;oBACI,QAAQ,EAAE,IAAI;oBACd,KAAK,EAAE,OAAO;iBACjB,CAAC,CAAC;aAC7B;YAID,IAAG,IAAA,gBAA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BACjB,CAAC,CAAC;aAC7B;YAID,IAAG,IAAA,gBAAS,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC,EAC3B;gBACI,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;aAC/B;YAED,kCAAkC;YAClC,IAAG,CAAC,CAAC,OAAO,IAAI,IAAI,CAAC,EACrB;gBACI,OAAO,CAAC,cAAc,CAAC,IAAI,EACJ,OAAO,EACP;oBACI,QAAQ,EAAE,IAAI;oBACd,KAAK,EAAE,IAAI;iBACd,CAAC,CAAC;aAC7B;YAED,IAAI,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC,GAAS,EAAE;gBAElC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,aAAa,CAAC,KAAK,CAAiC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;gBACrF,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,OAAO,CAAoB,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC;gBACtF,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;YACzB,CAAC,CAAA,EAAE,KAAK,CAAQ,CAAC;YAEjB,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;QACxB,CAAC,CAAC;QAEF,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;AACN,CAAC;AAnED,oCAmEC","sourcesContent":["import {PromiseOr} from '../types/async';\r\nimport {Action1, Func} from '../types/functions';\r\nimport {isFunction, isPresent} from '../utils/lang';\r\n\r\n/**\r\n * Adds special functionality to method call, that debounce method call for specified time\r\n * @param delay - Number of miliseconds that delays function call\r\n */\r\nexport function DebounceCall(delay: number): MethodDecorator\r\n{\r\n return function(_target: Object, propertyKey: string|symbol, descriptor: PropertyDescriptor)\r\n {\r\n const timeout = Symbol('ɵTimeout');\r\n const resolve = Symbol('ɵResolve');\r\n const result = Symbol('ɵResult');\r\n const originalValue: Func<any> = descriptor.value ?? descriptor.get?.();\r\n\r\n if(!isFunction(originalValue))\r\n {\r\n throw new Error(`Unable to apply @DebounceCall() decorator to '${propertyKey.toString()}', it is not a method.`);\r\n }\r\n\r\n descriptor.value = function<TResult>(this: {[timeout]: number|null, [resolve]: Action1<TResult|undefined>, [result]: Promise<TResult|undefined>}, ...args: unknown[]): Promise<TResult|undefined>\r\n {\r\n //result variable does not exists\r\n if(!(resolve in this) && !(result in this))\r\n {\r\n let resolveFn: Action1<TResult|undefined>|undefined;\r\n const promise = new Promise<TResult|undefined>(resolve => resolveFn = resolve);\r\n\r\n Reflect.defineProperty(this,\r\n resolve,\r\n {\r\n writable: true,\r\n value: resolveFn,\r\n });\r\n\r\n Reflect.defineProperty(this,\r\n result,\r\n {\r\n writable: true,\r\n value: promise,\r\n });\r\n }\r\n\r\n \r\n\r\n if(isPresent(this[timeout]))\r\n {\r\n clearTimeout(this[timeout]);\r\n }\r\n\r\n //timeout variable does not exists\r\n if(!(timeout in this))\r\n {\r\n Reflect.defineProperty(this,\r\n timeout,\r\n {\r\n writable: true,\r\n value: null,\r\n });\r\n }\r\n\r\n this[timeout] = setTimeout(async () =>\r\n {\r\n this[resolve](await originalValue.apply<any, any[], PromiseOr<TResult>>(this, args));\r\n this[result] = new Promise<TResult|undefined>(resolveFn => this[resolve] = resolveFn);\r\n this[timeout] = null;\r\n }, delay) as any;\r\n\r\n return this[result];\r\n };\r\n\r\n return descriptor;\r\n };\r\n}"]}
|
|
@@ -23,9 +23,10 @@ function WithSync() {
|
|
|
23
23
|
value: Promise.resolve(),
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
const syncPromise = this[sync];
|
|
27
27
|
let syncResolve;
|
|
28
28
|
this[sync] = new Promise(resolve => syncResolve = resolve);
|
|
29
|
+
yield syncPromise;
|
|
29
30
|
const result = yield originalValue.apply(this, args);
|
|
30
31
|
syncResolve === null || syncResolve === void 0 ? void 0 : syncResolve();
|
|
31
32
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withSync.decorator.cjs","sourceRoot":"","sources":["../../../src/decorators/withSync.decorator.ts"],"names":[],"mappings":";;;;AACA,wCAAyC;AAEzC;;GAEG;AACH,SAAgB,QAAQ;IAEpB,OAAO,UAAS,OAAe,EAAE,WAA0B,EAAE,UAA8B;;QAEvF,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;QAC7B,MAAM,aAAa,GAAc,MAAA,UAAU,CAAC,KAAK,mCAAI,MAAA,UAAU,CAAC,GAAG,0DAAI,CAAC;QAExE,IAAG,CAAC,IAAA,iBAAU,EAAC,aAAa,CAAC,EAC7B;YACI,MAAM,IAAI,KAAK,CAAC,6CAA6C,WAAW,CAAC,QAAQ,EAAE,wBAAwB,CAAC,CAAC;SAChH;QAED,UAAU,CAAC,KAAK,GAAG,UAA8D,GAAG,IAAe;;gBAE/F,+BAA+B;gBAC/B,IAAG,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,EAClB;oBACI,OAAO,CAAC,cAAc,CAAC,IAAI,EACJ,IAAI,EACJ;wBACI,QAAQ,EAAE,IAAI;wBACd,KAAK,EAAE,OAAO,CAAC,OAAO,EAAE;qBAC3B,CAAC,CAAC;iBAC7B;gBAED,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"withSync.decorator.cjs","sourceRoot":"","sources":["../../../src/decorators/withSync.decorator.ts"],"names":[],"mappings":";;;;AACA,wCAAyC;AAEzC;;GAEG;AACH,SAAgB,QAAQ;IAEpB,OAAO,UAAS,OAAe,EAAE,WAA0B,EAAE,UAA8B;;QAEvF,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;QAC7B,MAAM,aAAa,GAAc,MAAA,UAAU,CAAC,KAAK,mCAAI,MAAA,UAAU,CAAC,GAAG,0DAAI,CAAC;QAExE,IAAG,CAAC,IAAA,iBAAU,EAAC,aAAa,CAAC,EAC7B;YACI,MAAM,IAAI,KAAK,CAAC,6CAA6C,WAAW,CAAC,QAAQ,EAAE,wBAAwB,CAAC,CAAC;SAChH;QAED,UAAU,CAAC,KAAK,GAAG,UAA8D,GAAG,IAAe;;gBAE/F,+BAA+B;gBAC/B,IAAG,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,EAClB;oBACI,OAAO,CAAC,cAAc,CAAC,IAAI,EACJ,IAAI,EACJ;wBACI,QAAQ,EAAE,IAAI;wBACd,KAAK,EAAE,OAAO,CAAC,OAAO,EAAE;qBAC3B,CAAC,CAAC;iBAC7B;gBAED,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC/B,IAAI,WAAiC,CAAC;gBACtC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,WAAW,GAAG,OAAO,CAAC,CAAC;gBAC3D,MAAM,WAAW,CAAC;gBAElB,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,KAAK,CAAsB,IAAI,EAAE,IAAI,CAAC,CAAC;gBAE1E,WAAW,aAAX,WAAW,uBAAX,WAAW,EAAI,CAAC;gBAEhB,OAAO,MAAM,CAAC;YAClB,CAAC;SAAA,CAAC;QAEF,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;AACN,CAAC;AAvCD,4BAuCC","sourcesContent":["import {Func, NoopAction} from '../types/functions';\nimport {isFunction} from '../utils/lang';\n\n/**\n * Adds special functionality to async method call, that allows only to call this method only when previous execution was finished\n */\nexport function WithSync(): MethodDecorator\n{\n return function(_target: Object, propertyKey: string|symbol, descriptor: PropertyDescriptor)\n {\n const sync = Symbol('ɵSync');\n const originalValue: Func<any> = descriptor.value ?? descriptor.get?.();\n\n if(!isFunction(originalValue))\n {\n throw new Error(`Unable to apply @WithSync() decorator to '${propertyKey.toString()}', it is not a method.`);\n }\n\n descriptor.value = async function<TResult>(this: {[key: symbol]: Promise<void>}, ...args: unknown[]): Promise<TResult>\n {\n //sync variable does not exists\n if(!(sync in this))\n {\n Reflect.defineProperty(this,\n sync,\n {\n writable: true,\n value: Promise.resolve(),\n });\n }\n\n const syncPromise = this[sync];\n let syncResolve: NoopAction|undefined;\n this[sync] = new Promise(resolve => syncResolve = resolve);\n await syncPromise;\n\n const result = await originalValue.apply<any, any[], TResult>(this, args);\n\n syncResolve?.();\n\n return result;\n };\n\n return descriptor;\n };\n}"]}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debounceCall.decorator.d.ts","sourceRoot":"","sources":["debounceCall.decorator.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,eAAe,
|
|
1
|
+
{"version":3,"file":"debounceCall.decorator.d.ts","sourceRoot":"","sources":["debounceCall.decorator.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,eAAe,CAmE3D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withSync.decorator.d.ts","sourceRoot":"","sources":["withSync.decorator.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,QAAQ,IAAI,eAAe,
|
|
1
|
+
{"version":3,"file":"withSync.decorator.d.ts","sourceRoot":"","sources":["withSync.decorator.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,QAAQ,IAAI,eAAe,CAuC1C"}
|
package/version.bak
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
3.0.0
|
|
1
|
+
3.0.0
|