@-0/spool
Advanced tools
Comparing version 0.2.97 to 0.2.98
@@ -10,3 +10,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import { isFunction, isPromise, isArray } from "@thi.ng/checks"; | ||
import { isFunction, isArray } from "@thi.ng/checks"; | ||
import { pubsub } from "@thi.ng/rstream"; | ||
@@ -16,3 +16,2 @@ import { EquivMap } from "@thi.ng/associative"; | ||
import { stringify_type, xKeyError, key_index_err, diff_keys, stringify_fn } from "@-0/utils"; | ||
import { getIn } from "@thi.ng/paths"; | ||
const err_str = "🔥 Multiplex Spooling Interrupted 🔥"; | ||
@@ -69,2 +68,7 @@ const noSubEr = (c, i) => ` | ||
`; | ||
const NA_keys = (c, i) => { | ||
const knowns = [CMD_SUB$, CMD_ARGS, CMD_RESO, CMD_ERRO]; | ||
const [unknowns, unknown_kvs] = diff_keys(knowns, c); | ||
return xKeyError(err_str, c, unknown_kvs, i); | ||
}; | ||
export const keys_match = C => new EquivMap([ | ||
@@ -125,2 +129,3 @@ [[], "NO_ARGS"], | ||
let result = new EquivMap([ | ||
[{ K_M, args_type: "UNKNOWN" }, () => (console.warn(NA_keys(C, i), null))], | ||
[{ K_M, args_type: "OBJECT" }, () => __A], | ||
@@ -152,84 +157,3 @@ [{ K_M: "AE", args_type: "OBJECT" }, () => __A], | ||
} | ||
const props_type = keys_match(c); | ||
if (props_type === "NO_ARGS") { | ||
console.warn(no_args_error(c, i)); | ||
return (acc = null); | ||
} | ||
const sub$ = c[CMD_SUB$]; | ||
const args = c[CMD_ARGS]; | ||
const erro = c[CMD_ERRO]; | ||
const reso = c[CMD_RESO]; | ||
const knowns = [CMD_SUB$, CMD_ARGS, CMD_RESO, CMD_ERRO]; | ||
const [unknowns, unknown_kvs] = diff_keys(knowns, c); | ||
if (unknowns.length > 0) | ||
throw new Error(xKeyError(err_str, c, unknown_kvs, sub$, i)); | ||
const arg_type = stringify_type(args); | ||
let result = args; | ||
if (arg_type === "PRIMITIVE" && !sub$) { | ||
console.warn(noSubEr(c, i)); | ||
return acc; | ||
} | ||
if (arg_type === "OBJECT") { | ||
if (!sub$) | ||
return Object.assign(Object.assign({}, acc), args); | ||
out$.next(c); | ||
return Object.assign(Object.assign({}, acc), args); | ||
} | ||
if (arg_type === "NULLARY") { | ||
result = args(); | ||
console.log(`dispatching to ad-hoc stream: ${sub$.id}`); | ||
sub$.next(result); | ||
return acc; | ||
} | ||
if (arg_type !== "PROMISE" && reso) | ||
result = Promise.resolve(args); | ||
if (arg_type === "PROMISE") | ||
result = yield args.catch(e => e); | ||
if (arg_type === "UNARY") { | ||
let temp = args(acc); | ||
result = isPromise(temp) ? yield temp.catch(e => e) : temp; | ||
} | ||
if (result instanceof Error) { | ||
if (reso) { | ||
if (erro) { | ||
const err_type = stringify_type(erro); | ||
if (err_type === "NULLARY") { | ||
let ERR = erro(); | ||
if (getIn(ERR, [CMD_SUB$])) | ||
out$.next(ERR); | ||
return acc; | ||
} | ||
if (getIn(erro, [CMD_SUB$])) | ||
out$.next(erro); | ||
if (err_type === "BINARY") { | ||
if (getIn(erro(), [CMD_SUB$])) { | ||
let ERR_CMD = erro(acc, result); | ||
out$.next(ERR_CMD); | ||
} | ||
acc = erro(acc, result); | ||
} | ||
} | ||
acc = null; | ||
} | ||
acc === null || console.warn(`no \`erro\` (Error) handler set for ${sub$ || "error"} ${result}`); | ||
return acc; | ||
} | ||
if (reso) { | ||
let resolved = reso(acc, result); | ||
if (getIn(resolved, [CMD_SUB$])) | ||
return out$.next(resolved); | ||
result = resolved; | ||
} | ||
if (result === Object(result) && !sub$) | ||
return Object.assign(Object.assign({}, acc), result); | ||
if (result !== Object(result)) { | ||
if (!sub$) { | ||
console.warn(noSubEr(c, i)); | ||
return acc; | ||
} | ||
out$.next({ [CMD_SUB$]: sub$, [CMD_ARGS]: result }); | ||
return acc; | ||
} | ||
out$.next({ [CMD_SUB$]: sub$, [CMD_ARGS]: result }); | ||
return Object.assign(Object.assign({}, acc), result); | ||
return yield pattern_match(acc, c, out$, i); | ||
}), Promise.resolve({})) | ||
@@ -236,0 +160,0 @@ : (() => { |
@@ -42,3 +42,3 @@ import { map } from "@thi.ng/transducers"; | ||
if (unknowns.length > 0) { | ||
throw new Error(xKeyError(err_str, command, unknowns, sub$, undefined)); | ||
throw new Error(xKeyError(err_str, command, unknowns, undefined)); | ||
} | ||
@@ -45,0 +45,0 @@ if (src$) |
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "0.2.97", | ||
"version": "0.2.98", | ||
"description": "SPA framework built on top of http://thi.ng/umbrella ecosystem", | ||
@@ -44,4 +44,4 @@ "main": "./lib/index.js", | ||
"dependencies": { | ||
"@-0/keys": "^0.2.88", | ||
"@-0/utils": "^0.2.88" | ||
"@-0/keys": "^0.2.90", | ||
"@-0/utils": "^0.2.90" | ||
}, | ||
@@ -48,0 +48,0 @@ "devDependencies": { |
35718
274
Updated@-0/keys@^0.2.90
Updated@-0/utils@^0.2.90