pepka 1.9.1 → 1.9.3

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 CHANGED
@@ -96,22 +96,33 @@ 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
- this.catch(noop);
107
+ super.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) {
113
+ let _ff, _rj, _cancel_data;
110
114
  super((ff, rj) => {
111
- this.ff = ff;
112
- this.rj = rj;
113
- return fn(ff, rj);
115
+ _ff = ff;
116
+ _rj = rj;
117
+ _cancel_data = fn(ff, rj);
114
118
  });
119
+ this.oncancel = oncancel;
120
+ const set_cb = () => { this.ff = _ff; this.rj = _rj; this._cancel_data = _cancel_data; };
121
+ // @ts-ignore-next
122
+ if (!isUndef(_ff) || !isUndef(_rj))
123
+ set_cb();
124
+ else
125
+ setTimeout(set_cb);
115
126
  }
116
127
  }
117
128
 
@@ -785,7 +796,7 @@ const throttle = (time, fn) => {
785
796
  return res;
786
797
  };
787
798
  };
788
- const wait = (time) => new QPromise((ff) => setTimeout(ff, time));
799
+ const wait = (time) => new QPromise((ff) => setTimeout(ff, time), (timeout) => clearTimeout(timeout));
789
800
 
790
801
  // TODO: possibly introduce a second argument limiting unfolding.
791
802
  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,33 @@ 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
- this.catch(noop);
105
+ super.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) {
111
+ let _ff, _rj, _cancel_data;
108
112
  super((ff, rj) => {
109
- this.ff = ff;
110
- this.rj = rj;
111
- return fn(ff, rj);
113
+ _ff = ff;
114
+ _rj = rj;
115
+ _cancel_data = fn(ff, rj);
112
116
  });
117
+ this.oncancel = oncancel;
118
+ const set_cb = () => { this.ff = _ff; this.rj = _rj; this._cancel_data = _cancel_data; };
119
+ // @ts-ignore-next
120
+ if (!isUndef(_ff) || !isUndef(_rj))
121
+ set_cb();
122
+ else
123
+ setTimeout(set_cb);
113
124
  }
114
125
  }
115
126
 
@@ -783,7 +794,7 @@ const throttle = (time, fn) => {
783
794
  return res;
784
795
  };
785
796
  };
786
- const wait = (time) => new QPromise((ff) => setTimeout(ff, time));
797
+ const wait = (time) => new QPromise((ff) => setTimeout(ff, time), (timeout) => clearTimeout(timeout));
787
798
 
788
799
  // TODO: possibly introduce a second argument limiting unfolding.
789
800
  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.1",
44
+ "version": "1.9.3",
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>((ff) => setTimeout(ff, time))
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,24 @@ 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
- this.catch(noop)
26
+ super.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) {
32
+ let _ff: AnyFunc, _rj: AnyFunc, _cancel_data: any
30
33
  super((ff, rj) => {
31
- this.ff=ff; this.rj = rj
32
- return fn(ff, rj)
34
+ _ff=ff; _rj=rj
35
+ _cancel_data = fn(ff, rj)
33
36
  })
37
+ const set_cb = () => {this.ff=_ff; this.rj=_rj; this._cancel_data=_cancel_data}
38
+ // @ts-ignore-next
39
+ if(!isUndef(_ff) || !isUndef(_rj)) set_cb()
40
+ else setTimeout(set_cb)
34
41
  }
35
42
  }