pepka 1.9.3 → 1.9.4

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/utils.ts +5 -10
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.3",
44
+ "version": "1.9.4",
45
45
  "devDependencies": {
46
46
  "@rollup/plugin-commonjs": "^29.0.2",
47
47
  "@rollup/plugin-node-resolve": "^16.0.3",
package/src/utils.ts CHANGED
@@ -4,6 +4,7 @@ import { AnyFunc, AnyObject } from "./types"
4
4
  export const undef = undefined
5
5
  export const nul = null
6
6
  export const inf = Infinity
7
+ export const not_assigned = Symbol()
7
8
  export const to = (s: any) => typeof s
8
9
  export const isNull = <T extends any>(s: T) => (s===nul) as T extends null ? true : false
9
10
  export const isUndef = <T extends any>(s: T) => (s===undef) as T extends undefined ? true : false
@@ -18,25 +19,19 @@ export const isNil = <T extends any>(s: T) => (isNull(s) || isUndef(s)) as T ext
18
19
 
19
20
  export class QPromise<T> extends Promise<T> {
20
21
  private ff: AnyFunc
21
- private rj: AnyFunc
22
22
  private _cancel_data: any
23
23
  public cancel(resolve = false) {
24
24
  if(resolve) this.ff()
25
- else {
26
- super.catch(noop)
27
- this.rj('canceled')
28
- this.oncancel(this._cancel_data)
29
- }
25
+ this.oncancel(this._cancel_data)
30
26
  }
31
27
  constructor(fn: AnyFunc<any, [AnyFunc, AnyFunc, AnyFunc?]>, private oncancel = noop) {
32
- let _ff: AnyFunc, _rj: AnyFunc, _cancel_data: any
28
+ let _cancel_data: any = not_assigned
33
29
  super((ff, rj) => {
34
- _ff=ff; _rj=rj
35
30
  _cancel_data = fn(ff, rj)
36
31
  })
37
- const set_cb = () => {this.ff=_ff; this.rj=_rj; this._cancel_data=_cancel_data}
32
+ const set_cb = () => this._cancel_data=_cancel_data
38
33
  // @ts-ignore-next
39
- if(!isUndef(_ff) || !isUndef(_rj)) set_cb()
34
+ if(_cancel_data!==not_assigned) set_cb()
40
35
  else setTimeout(set_cb)
41
36
  }
42
37
  }