From 64bfedb0f5369c6c85948d200e482ccd103c1a7a Mon Sep 17 00:00:00 2001 From: E0SelmY4V-PC <2507917746@qq.com> Date: Wed, 21 Dec 2022 02:09:49 +0800 Subject: [PATCH] ver: 1.1.2022112000 --- main.d.ts | 99 +++++++++++++++--------------- main.js | 166 +++++++++++++++++++++++++++------------------------ package.json | 4 +- 3 files changed, 140 insertions(+), 129 deletions(-) diff --git a/main.d.ts b/main.d.ts index 5bc5484..630af51 100644 --- a/main.d.ts +++ b/main.d.ts @@ -1,14 +1,13 @@ import { SntXcrNum, - ArrayAccur, Accur, ArrayLtdSplited, Transposed, } from 'accurtype' export namespace scpoProce { type CbNor

= (...arg: [...P, ...T]) => R - type CbCur

= CbNor<[CbNor | never, CbNor | never], R, never[]> - type CbNxt

= CbNor<[CbNor | never, CbNor | never, ...P0], R, never[]> + type CbCur

= CbNor<[CbNor, CbNor], R, any[]> + type CbNxt

= CbNor<[CbNor, CbNor, ...P0], R, any[]> type STimer = number | null type ListGot = L extends ArrayLike ? L[0] extends T ? L[0] : L : L const isBrowser: boolean @@ -19,12 +18,23 @@ export namespace scpoProce { function getList(list: T): ListGot> type ProceN = Proce type ProceArgs = T extends Proce ? A : [T] + type ProceErrs = T extends Proce ? A : [] type ProceFilled = T extends 0 ? A : ProceFilled, [ProceN, ...A]> - type ProceTaked = D extends 0 ? T : T extends [Proce, ...any[]] ? ProceTaked> : T - type SnakeList = T extends [infer P0 extends any[], infer P extends any[], ...infer K extends any[]] ? [CbNxt, ...SnakeList<[P, ...K], E>] : [] - type SnakeRslt = T extends [CbNxt, ...infer K extends any[]] ? [...(F extends 0 ? [S, P] : [P]), ...SnakeRslt] : []; + type ProceTaked

= D extends 0 ? Proce : P extends [Proce, ...any[]] ? ProceTaked> : Proce + // type SnakeList = T extends [infer P0 extends any[], infer P extends any[], ...infer K extends any[]] ? [CbNxt, ...SnakeList<[P, ...K], E>] : [] + // type SnakeRslt = T extends [CbNxt, ...infer K extends any[]] ? [...(F extends 0 ? [S, P] : [P]), ...SnakeRslt] : []; type OnedArgs = T extends (infer K)[] ? ProceArgs : never; + type LtdUedProce = T extends [infer K, ...infer T1] ? [ProceArgs, ...LtdUedProce] : [] + type UedProce = ArrayLtdSplited extends [infer T0, (infer S)[], infer T2] ? [...LtdUedProce, ...(ProceArgs extends never ? [] : ProceArgs[]), ...LtdUedProce] : [] + type LtdUedProceE = T extends [infer K, ...infer T1] ? ProceErrs | LtdUedProceE : never + type UedProceE = ArrayLtdSplited extends [infer T0, (infer S)[], infer T2] ? LtdUedProceE | ProceErrs | LtdUedProceE : [] function getId(): number + function doRtn, E extends any[] = ProceErrs>(_t: T, expr: CbNor, param: P | P[0] | E | E[0]): R + function act, E extends any[] = ProceErrs>(_t: T, doexpr: CbNxt | CbCur, args: R0): R + function clear>(_t: T, param: P | P[0]): void + function exeordo>(_t: T, param: E | E[0]): any + function toss>(_t: T, errObj: E[0]): void + function tpus, E extends any[] = ProceErrs>(_t: T, todo?: CbNor, ordo?: CbNor): void class Proce

{ constructor(doexpr?: CbCur, config?: Config, cleared?: boolean) id: number @@ -36,68 +46,54 @@ export namespace scpoProce { lastRtn: P | P[0] | E | E[0] lastErr: STimer lastDef: STimer - config: ConfigClass + config: ConfigClassN pointer: number before?: ProceN uncaught: boolean - doRtn(expr: CbNor, param: P | P[0] | E | E[0]): R - act(doexpr: CbCur): R - act(doexpr: CbNxt | CbCur, args: R0): R - clear(param: P | P[0]): void - exeordo(param: E | E[0]): any - toss: (errObj: E[0]) => void getBefore(n?: ProceArray): ProceArray - setBefore(n: ProceArray | ProceN[]): void - tpus(todo?: CbNor, ordo?: CbNor): void - then(todo?: CbNor, ordo?: CbNor): Proce<[R]> - trap(ordo?: CbNor): Proce<[R]> - next(doexpr?: CbNxt, ordo?: CbNor, config?: Config): Proce - take(depth?: D): Proce, E> - take, E>>(todo: t.tf, ordo?: t.tf, depth?: D): Proce<[R]> - conf(config?: Config, ordo?: CbNor): t.cp + setBefore(n?: ProceArray | ProceN[]): Proce + then(todo?: CbNor): Proce<[RT], E1 | E> + then(todo?: CbNor, ordo?: CbNor): Proce<[RT | RO], E1> + trap(ordo?: CbNor): Proce | Proce<[RO], E1> + next(doexpr?: CbNxt, ordo?: CbNor, config?: Config): Proce + take(depth?: D): ProceTaked + take>(todo: t.tf, ordo?: t.tf, depth?: D): Proce<[RT | RO]> + conf(config?: Config, ordo?: CbNor): t.cp configAll(n?: Config): Proce todo, P1 extends A[]>(...n: P1): Proce ordo, E1 extends A[]>(...n: E1): Proce<[], E1> - snake(n?: []): Proce - snake, A extends CbNxt[], E1 extends any[], B extends any[] = t.sf>(n: t.sm): t.st - snake, A extends CbNxt[], E1 extends any[], B extends any[] = t.sf>(...n: t.sm): t.st - one, T extends ArrayAccur>(n: T): Proce, []> - one, T extends A[]>(...n: T): Proce, []> - all, T extends ArrayAccur>(n: T): Proce>> - all, T extends A[]>(...n: T): Proce>> + snake(h: H, ...n: T): t.sn + one(h: H, ...n: T): Proce, UedProceE> + all(h: H, ...n: T): Proce>, UedProceE> } - function then(todo?: CbNor<[], R, void[]>, ordo?: CbNor<[], R, void[]>): Proce<[R]> - function trap(ordo?: CbNor<[], R, void[]>): Proce<[R]> - function next(doexpr?: CbNxt, ordo?: CbNor, config?: Config): Proce - function conf(config?: Config, ordo?: CbNor<[], E1, void[]>): t.cp<[], E1> + function then(todo?: CbNor<[], RT, any[]>, ordo?: CbNor<[]>): Proce<[RT], E1> + function trap(ordo?: CbNor<[]>): Proce<[], []> + function next(doexpr?: CbNxt, ordo?: CbNor, config?: Config): Proce + function conf(config?: Config, ordo?: CbNor<[], E1, any[]>): t.cp<[], E1> function configAll(): Proce<[], []> function todo, P1 extends A[]>(...n: P1): Proce function ordo, E1 extends A[]>(...n: E1): Proce<[], E1> - function snake(n?: []): Proce<[], []> - function snake, A extends CbNxt[], E1 extends any[], B extends any[] = t.sf>(n: t.sm): t.st - function snake, A extends CbNxt[], E1 extends any[], B extends any[] = t.sf>(...n: t.sm): t.st - function one, T extends ArrayAccur>(n: T): Proce, []> - function one, T extends A[]>(...n: T): Proce, []> - function all, T extends ArrayAccur>(n: T): Proce>> - function all, T extends A[]>(...n: T): Proce>> - type LtdUedProce = T extends [infer K, ...infer T1] ? [ProceArgs, ...LtdUedProce] : [] - type UedProce = ArrayLtdSplited extends [infer T0, (infer S)[], infer T2] ? [...LtdUedProce, ...(ProceArgs extends never ? [] : ProceArgs[]), ...LtdUedProce] : [] + function snake(h: H, ...n: T): t.sn + function one(h: H, ...n: T): Proce, UedProceE> + function all(h: H, ...n: T): Proce>, UedProceE> namespace t { - type tf = CbNor ? W extends 0 ? P : E : W extends 0 ? [] : [any], R, void[]> - type cp

= Proce

- type sf = SnakeRslt<[CbNxt ? K : any[], P>, ...A]> - type sm = SnakeList | [F, ...A] - type st = Proce + type tf = CbNor ? W extends 0 ? P : E : W extends 0 ? [] : [any], R, any[]> + type cp

= Proce

+ // type sf = SnakeRslt<[CbNxt ? K : any[], P>, ...A]> + // type sm = SnakeList | [F, ...A] + // type st = Proce + type sn = Proce[] ? P1 : any[], T extends CbNxt[] ? E1 : [any]> extends Proce ? Proce : Proce } class ProceArray

extends Array> { constructor(...proce: Proce[]) - then(todo?: CbNor, ordo?: CbNor): void - trap(ordo?: CbNor): void - supp(ordo?: CbNor): void + then(todo?: CbNor, ordo?: CbNor): void + trap(ordo?: CbNor): void + supp(ordo?: CbNor): void index: { [id: number]: true } pointer: number } type Config = Omit | ConfigClass + type ConfigClassN = ConfigClass class ConfigClass

{ constructor(n: Config, proc?: Proce) static configAll(n?: Config): void @@ -108,13 +104,14 @@ export namespace scpoProce { todo?: CbNor

ordo?: CbNor } + type Nxtable = ProceN | typeof scpoProce } /** * 幻想私社异步过程类 * @author E0SelmY4V - * @version 1.1.2022112000 + * @version 1.1.2022122000 * @link https://github.com/E0SelmY4V/scpo-proce */ -export function scpoProce

(doexpr: scpoProce.CbCur, config?: scpoProce.Config): scpoProce.Proce

+export function scpoProce

(doexpr: scpoProce.CbCur, config?: scpoProce.Config): scpoProce.Proce export function scpoProce, P extends A[]>(...arg: P): scpoProce.Proce export default scpoProce \ No newline at end of file diff --git a/main.js b/main.js index 2c648e2..5bfd815 100644 --- a/main.js +++ b/main.js @@ -1,7 +1,7 @@ /** * 幻想私社异步过程类 * @author E0SelmY4V - * @version 1.1.2022112000 + * @version 1.1.2022122000 * @link https://github.com/E0SelmY4V/scpo-proce */ 'use strict'; @@ -59,13 +59,13 @@ } var proto = { then: function (todo, ordo) { - for (var i = this.length - 1; i >= 0; i--) this[i].tpus(todo, ordo); + for (var i = this.length - 1; i >= 0; i--) tpus(this[i], todo, ordo); }, trap: function (ordo) { return this.then(null, ordo); }, supp: function (ordo) { - for (var i = this.length - 1; i >= 0; i--) if (this[i].uncaught) this[i].tpus(null, ordo); + for (var i = this.length - 1; i >= 0; i--) if (this[i].uncaught) tpus(this[i], null, ordo); }, pointer: 0, index: null @@ -100,9 +100,89 @@ pipe.ConfigClass = ConfigClass; pipe.config = new ConfigClass(); + function doRtn(_t, expr, param) { + if (_t.nmArg) return expr(param); + else { + _t.nmArg = true; + return apply(expr, null, param); + } + } + pipe.doRtn; + + function act(_t, doexpr, args) { + var params = [ + function () { if (noClear) noClear = false, clear(_t, arguments); }, + function () { if (noClear) noClear = false, clear(_t, exeordo(_t, arguments)); } + ], noClear = true; + if (args) for (var i = 0; i < args.length; i++) params.push(args[i]); + try { + var r = apply(doexpr, _t, params); + return _t.config.trap !== 'none' && isThenable(r) && (typeof r.getBefore === 'function' + ? r.getBefore(new ProceArray())[ + _t.config.trap === 'all' ? 'trap' : 'supp' + ](params[1]) + : r.then(null, params[1]) + ), _t.acted = true, r; + } catch (errObj) { _t.acted = true; return params[1](errObj); } + } + pipe.act = act; + + function clear(_t, param) { + var i = _t.pointer, q = _t.queuetodo, f = true; + while (++i < q.length) if (typeof q[i] === 'function') { + q[i].hidden || (f = false); + try { param = doRtn(_t, q[i], param); } + catch (errObj) { _t.pointer = i, param = exeordo(_t, errObj), i = _t.pointer; } + } + f && (_t.lastDef = setTimeout(function () { + _t.then(_t.config.todo, _t.config.ordo); + })), _t.lastRtn = param, _t.cleared = true; + } + pipe.clear = clear; + + function exeordo(_t, param) { + var i = _t.pointer, q = _t.queueordo; + while (++i < q.length) if (typeof q[i] === 'function') { + _t.pointer = i; + try { return doRtn(_t, q[i], param); } + catch (errObj) { return exeordo(_t, errObj); } + } + return _t.pointer = i, toss(_t, _t.nmArg ? param : param[0]), param; + } + pipe.exeordo = exeordo; + + function toss(_t, errObj) { + _t.lastErr = setTimeout(function () { + if (_t.lastDef !== null) return toss(_t, errObj); + else if (isBrowser && !window.console) throw errObj; + else return console.error('scpo-proce Uncaught', errObj); + }); + } + pipe.toss = toss; + + function tpus(_t, todo, ordo) { + var orf = typeof ordo === 'function', tof = typeof todo === 'function'; + if (_t.uncaught) _t.uncaught = !orf; + if (_t.cleared) { + _t.pointer++; + var hid = todo && todo.hidden; + hid || (clearTimeout(_t.lastDef), _t.lastDef = null); + try { + _t.lastErr === null ? tof && ( + _t.lastRtn = doRtn(_t, todo, _t.lastRtn) + ) : orf && ( + hid && (clearTimeout(_t.lastDef), _t.lastDef = null), + clearTimeout(_t.lastErr), _t.lastErr = null, + _t.lastRtn = doRtn(_t, ordo, _t.lastRtn) + ); + } catch (errObj) { _t.lastRtn = errObj, toss(_t, errObj); } + } else _t.queueordo.push(ordo), _t.queuetodo.push(todo); + } + pipe.tpus = tpus; + function Proce(doexpr, config, cleared) { this.queuetodo = [], this.queueordo = [], this.config = new ConfigClass(config, this), this.id = getId(); - cleared ? this.cleared = true : typeof doexpr === 'function' && this.act(doexpr); + cleared ? this.cleared = true : typeof doexpr === 'function' && act(this, doexpr); } Proce.prototype = { id: NaN, @@ -118,81 +198,12 @@ pointer: -1, before: null, uncaught: true, - doRtn: function (expr, param) { - if (this.nmArg) return expr(param); - else { - this.nmArg = true; - return apply(expr, null, param); - } - }, - act: function (doexpr, args) { - var t = this, params = [ - function () { if (noClear) noClear = false, t.clear(arguments); }, - function () { if (noClear) noClear = false, t.clear(t.exeordo(arguments)); } - ], noClear = true; - if (args) for (var i = 0; i < args.length; i++) params.push(args[i]); - try { - var r = apply(doexpr, this, params); - return this.config.trap !== 'none' && isThenable(r) && (typeof r.getBefore === 'function' - ? r.getBefore(new ProceArray())[ - this.config.trap === 'all' ? 'trap' : 'supp' - ](params[1]) - : r.then(null, params[1]) - ), this.acted = true, r; - } catch (errObj) { this.acted = true; return params[1](errObj); } - }, - clear: function (param) { - var i = this.pointer, q = this.queuetodo, f = true, t = this; - while (++i < q.length) if (typeof q[i] === 'function') { - q[i].hidden || (f = false); - try { param = this.doRtn(q[i], param); } - catch (errObj) { this.pointer = i, param = this.exeordo(errObj), i = this.pointer; } - } - f && (this.lastDef = setTimeout(function () { - t.then(t.config.todo, t.config.ordo); - })), this.lastRtn = param, this.cleared = true; - }, - exeordo: function (param) { - var i = this.pointer, q = this.queueordo; - while (++i < q.length) if (typeof q[i] === 'function') { - this.pointer = i; - try { return this.doRtn(q[i], param); } - catch (errObj) { return this.exeordo(errObj); } - } - return this.pointer = i, this.toss(this.nmArg ? param : param[0]), param; - }, - toss: function (errObj) { - var t = this; - this.lastErr = setTimeout(function () { - if (t.lastDef !== null) return t.toss(errObj); - else if (isBrowser && !window.console) throw errObj; - else return console.error('scpo-proce Uncaught', errObj); - }); - }, - tpus: function (todo, ordo) { - var orf = typeof ordo === 'function', tof = typeof todo === 'function'; - if (this.uncaught) this.uncaught = !orf; - if (this.cleared) { - this.pointer++; - var hid = todo && todo.hidden; - hid || (clearTimeout(this.lastDef), this.lastDef = null); - try { - this.lastErr === null ? tof && ( - this.lastRtn = this.doRtn(todo, this.lastRtn) - ) : orf && ( - hid && (clearTimeout(this.lastDef), this.lastDef = null), - clearTimeout(this.lastErr), this.lastErr = null, - this.lastRtn = this.doRtn(ordo, this.lastRtn) - ); - } catch (errObj) { this.lastRtn = errObj, this.toss(errObj); } - } else this.queueordo.push(ordo), this.queuetodo.push(todo); - }, then: function (todo, ordo) { if (!isProce(this)) return new Proce(null, null, true).then(todo, ordo); if (this.config.trap !== 'none') this.getBefore()[ this.config.trap === 'all' ? 'trap' : 'supp' ](ordo); - return this.tpus(todo, ordo), this; + return tpus(this, todo, ordo), this; }, trap: function (ordo) { return this.then(null, ordo); @@ -201,7 +212,7 @@ if (!isProce(this)) return new Proce(null, null, true).next(doexpr, ordo, config); if (typeof doexpr !== 'function') return this.then(doexpr, ordo).conf(config); var proc = new Proce(null, this.config.get(config)), - cf = function () { return proc.act(doexpr, arguments); }; + cf = function () { return act(proc, doexpr, arguments); }; return cf.hidden = true, this.then(cf, ordo), proc.before = this, proc.trap(ordo); }, take: function (todo, ordo, depth) { @@ -219,8 +230,9 @@ ) : this.before.getBefore(new ProceArray()) : n || new ProceArray(); }, setBefore: function (n) { - if (n && (n.pointer || (n.pointer = 0)) !== n.length) return (this.before = n[n.pointer++]).setBefore(n); + if (n && (n.pointer || (n.pointer = 0)) !== n.length) (this.before = n[n.pointer++]).setBefore(n); else delete this.before; + return this; }, conf: function (config, ordo) { if (!isProce(this)) return new Proce(null, null, true).conf(config); @@ -237,7 +249,7 @@ }, ordo: function () { var proc = new Proce(null, null, true); - return proc.lastRtn = arguments, proc.toss(arguments[0]), proc; + return proc.lastRtn = arguments, toss(proc, arguments[0]), proc; }, all: function () { var l = getList(arguments), r = [[]], i = l.length, c = i; diff --git a/package.json b/package.json index 840e6da..a8c6ee5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scpo-proce", - "version": "1.1.2022112000", + "version": "1.1.2022122000", "description": "Make your async programming easier", "main": "main.js", "scripts": {}, @@ -14,6 +14,8 @@ "callback", "ie", "ie6", + "utility", + "utilities", "util" ], "author": "e0selmy4v",