pepka 1.9.1 → 1.9.2
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/dist/bundle.cjs +7 -3
- package/dist/bundle.d.ts +5 -2
- package/dist/bundle.mjs +7 -3
- package/package.json +1 -1
- package/src/timers.ts +4 -1
- package/src/utils.ts +4 -2
package/dist/bundle.cjs
CHANGED
|
@@ -96,22 +96,26 @@ const isStr = (s) => (to(s) === 'string');
|
|
|
96
96
|
const isObj = (s) => (!isNull(s) && to(s) === 'object');
|
|
97
97
|
const isNil = (s) => (isNull(s) || isUndef(s));
|
|
98
98
|
class QPromise extends Promise {
|
|
99
|
+
oncancel;
|
|
99
100
|
ff;
|
|
100
101
|
rj;
|
|
102
|
+
_cancel_data;
|
|
101
103
|
cancel(resolve = false) {
|
|
102
104
|
if (resolve)
|
|
103
105
|
this.ff();
|
|
104
106
|
else {
|
|
105
107
|
this.catch(noop);
|
|
106
108
|
this.rj('canceled');
|
|
109
|
+
this.oncancel(this._cancel_data);
|
|
107
110
|
}
|
|
108
111
|
}
|
|
109
|
-
constructor(fn) {
|
|
112
|
+
constructor(fn, oncancel = noop) {
|
|
110
113
|
super((ff, rj) => {
|
|
111
114
|
this.ff = ff;
|
|
112
115
|
this.rj = rj;
|
|
113
|
-
|
|
116
|
+
this._cancel_data = fn(ff, rj);
|
|
114
117
|
});
|
|
118
|
+
this.oncancel = oncancel;
|
|
115
119
|
}
|
|
116
120
|
}
|
|
117
121
|
|
|
@@ -785,7 +789,7 @@ const throttle = (time, fn) => {
|
|
|
785
789
|
return res;
|
|
786
790
|
};
|
|
787
791
|
};
|
|
788
|
-
const wait = (time) => new QPromise((ff) => setTimeout(ff, time));
|
|
792
|
+
const wait = (time) => new QPromise((ff) => setTimeout(ff, time), (timeout) => clearTimeout(timeout));
|
|
789
793
|
|
|
790
794
|
// TODO: possibly introduce a second argument limiting unfolding.
|
|
791
795
|
const uncurry = (fn) => (...args) => qreduce(((fn, arg) => fn ? fn(arg) : fn), fn, args);
|
package/dist/bundle.d.ts
CHANGED
|
@@ -240,13 +240,16 @@ export declare const qpush: {
|
|
|
240
240
|
};
|
|
241
241
|
export declare const isNil: <T extends any>(s: T) => T extends (null | undefined) ? true : false;
|
|
242
242
|
export declare class QPromise<T> extends Promise<T> {
|
|
243
|
+
private oncancel;
|
|
243
244
|
private ff;
|
|
244
245
|
private rj;
|
|
246
|
+
private _cancel_data;
|
|
245
247
|
cancel(resolve?: boolean): void;
|
|
246
248
|
constructor(fn: AnyFunc<any, [
|
|
247
249
|
AnyFunc,
|
|
248
|
-
AnyFunc
|
|
249
|
-
|
|
250
|
+
AnyFunc,
|
|
251
|
+
AnyFunc?
|
|
252
|
+
]>, oncancel?: (...args: any[]) => any);
|
|
250
253
|
}
|
|
251
254
|
export declare const take: (argN: number) => (...args: any[]) => any;
|
|
252
255
|
export declare const ifElse: (...args: AnyArgs) => any;
|
package/dist/bundle.mjs
CHANGED
|
@@ -94,22 +94,26 @@ const isStr = (s) => (to(s) === 'string');
|
|
|
94
94
|
const isObj = (s) => (!isNull(s) && to(s) === 'object');
|
|
95
95
|
const isNil = (s) => (isNull(s) || isUndef(s));
|
|
96
96
|
class QPromise extends Promise {
|
|
97
|
+
oncancel;
|
|
97
98
|
ff;
|
|
98
99
|
rj;
|
|
100
|
+
_cancel_data;
|
|
99
101
|
cancel(resolve = false) {
|
|
100
102
|
if (resolve)
|
|
101
103
|
this.ff();
|
|
102
104
|
else {
|
|
103
105
|
this.catch(noop);
|
|
104
106
|
this.rj('canceled');
|
|
107
|
+
this.oncancel(this._cancel_data);
|
|
105
108
|
}
|
|
106
109
|
}
|
|
107
|
-
constructor(fn) {
|
|
110
|
+
constructor(fn, oncancel = noop) {
|
|
108
111
|
super((ff, rj) => {
|
|
109
112
|
this.ff = ff;
|
|
110
113
|
this.rj = rj;
|
|
111
|
-
|
|
114
|
+
this._cancel_data = fn(ff, rj);
|
|
112
115
|
});
|
|
116
|
+
this.oncancel = oncancel;
|
|
113
117
|
}
|
|
114
118
|
}
|
|
115
119
|
|
|
@@ -783,7 +787,7 @@ const throttle = (time, fn) => {
|
|
|
783
787
|
return res;
|
|
784
788
|
};
|
|
785
789
|
};
|
|
786
|
-
const wait = (time) => new QPromise((ff) => setTimeout(ff, time));
|
|
790
|
+
const wait = (time) => new QPromise((ff) => setTimeout(ff, time), (timeout) => clearTimeout(timeout));
|
|
787
791
|
|
|
788
792
|
// TODO: possibly introduce a second argument limiting unfolding.
|
|
789
793
|
const uncurry = (fn) => (...args) => qreduce(((fn, arg) => fn ? fn(arg) : fn), fn, args);
|
package/package.json
CHANGED
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"prod": "npm run gentypes && npm run prod:es && npm run prod:cjs",
|
|
42
42
|
"all": "npm run dev && npm run prod"
|
|
43
43
|
},
|
|
44
|
-
"version": "1.9.
|
|
44
|
+
"version": "1.9.2",
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@rollup/plugin-commonjs": "^29.0.2",
|
|
47
47
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
package/src/timers.ts
CHANGED
|
@@ -26,4 +26,7 @@ export const throttle = <T extends AnyFunc>(time: number, fn: T) => {
|
|
|
26
26
|
return res
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
export const wait = (time: number) => new QPromise<any>(
|
|
29
|
+
export const wait = (time: number) => new QPromise<any>(
|
|
30
|
+
(ff) => setTimeout(ff, time),
|
|
31
|
+
(timeout: any) => clearTimeout(timeout)
|
|
32
|
+
)
|
package/src/utils.ts
CHANGED
|
@@ -19,17 +19,19 @@ export const isNil = <T extends any>(s: T) => (isNull(s) || isUndef(s)) as T ext
|
|
|
19
19
|
export class QPromise<T> extends Promise<T> {
|
|
20
20
|
private ff: AnyFunc
|
|
21
21
|
private rj: AnyFunc
|
|
22
|
+
private _cancel_data: any
|
|
22
23
|
public cancel(resolve = false) {
|
|
23
24
|
if(resolve) this.ff()
|
|
24
25
|
else {
|
|
25
26
|
this.catch(noop)
|
|
26
27
|
this.rj('canceled')
|
|
28
|
+
this.oncancel(this._cancel_data)
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
|
-
constructor(fn: AnyFunc<any, [AnyFunc, AnyFunc]
|
|
31
|
+
constructor(fn: AnyFunc<any, [AnyFunc, AnyFunc, AnyFunc?]>, private oncancel = noop) {
|
|
30
32
|
super((ff, rj) => {
|
|
31
33
|
this.ff=ff; this.rj = rj
|
|
32
|
-
|
|
34
|
+
this._cancel_data = fn(ff, rj)
|
|
33
35
|
})
|
|
34
36
|
}
|
|
35
37
|
}
|