From 1d7a92521b343989207f63527613cc9b33f88aaa Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Sun, 19 Apr 2020 21:43:47 +0200 Subject: [PATCH] StatefulEvt.prototype.statefulPipe becomes pipe; no need to increace the api surface --- deno_dist/lib/StatefulEvt.ts | 18 ++++-- .../types/interfaces/StatefulReadonlyEvt.ts | 59 +++++++++--------- deno_dist/test/deno_index.ts | 3 +- deno_dist/test/index.ts | 2 +- deno_dist/test/test73.ts | 8 +-- deno_dist/test/test87.ts | 4 +- deno_dist/test/test89.ts | 2 +- deno_dist/test/test90.ts | 40 +++++++++++++ dist/lib/StatefulEvt.js | 14 +++-- dist/lib/StatefulEvt.js.map | 2 +- .../types/interfaces/StatefulReadonlyEvt.d.ts | 57 +++++++++--------- dist/tsconfig.tsbuildinfo | 44 +++++++++----- package-lock.json | 2 +- package.json | 2 +- src/lib/StatefulEvt.ts | 17 ++++-- .../types/interfaces/StatefulReadonlyEvt.ts | 60 ++++++++++--------- src/test/deno_index.ts | 3 +- src/test/index.ts | 2 +- src/test/test73.ts | 8 +-- src/test/test87.ts | 4 +- src/test/test89.ts | 2 +- src/test/test90.ts | 40 +++++++++++++ 22 files changed, 259 insertions(+), 134 deletions(-) create mode 100644 deno_dist/test/test90.ts create mode 100644 src/test/test90.ts diff --git a/deno_dist/lib/StatefulEvt.ts b/deno_dist/lib/StatefulEvt.ts index 6303fe29..e83b4e20 100644 --- a/deno_dist/lib/StatefulEvt.ts +++ b/deno_dist/lib/StatefulEvt.ts @@ -6,6 +6,7 @@ import { importProxy } from "./importProxy.ts"; import { invokeOperator } from "./util/invokeOperator.ts"; import { Operator } from "./types/Operator.ts"; import { parsePropsFromArgs } from "./Evt.parsePropsFromArgs.ts"; +import { CtxLike } from "./types/interfaces/CtxLike.ts"; type Diff = import("./types/interfaces/index.ts").Diff; type NonPostableEvt = import("./types/interfaces/index.ts").NonPostableEvt; type StatefulReadonlyEvt= import("./types/interfaces/index.ts").StatefulReadonlyEvt; @@ -94,11 +95,10 @@ class StatefulEvtImpl extends Evt implements StatefulEvt { } + pipe(...args: any[]): StatefulEvt { - statefulPipe(...args: any[]): StatefulEvt { - - const evt = this - .pipe(...(args as Parameters)) + const evt = super + .pipe(...(args as Parameters)) ; const opResult = invokeOperator( @@ -111,8 +111,9 @@ class StatefulEvtImpl extends Evt implements StatefulEvt { if (Operator.fλ.Result.NotMatched.match(opResult)) { throw new Error([ - "Operator do not match current state", - "use evt.pipe([ctx], op).toStatic(initialState)", + "Cannot pipe StatefulEvt because the operator does not match", + "it's current state.", + "Use evt.toStateless([ctx]).pipe(op).toStatic(initialState)", "to be sure the StatefulEvt is correctly initialized" ].join(" ")); @@ -122,6 +123,11 @@ class StatefulEvtImpl extends Evt implements StatefulEvt { } + /** Return a stateless copy */ + toStateless(ctx?: CtxLike): Evt { + return !!ctx ? super.pipe(ctx) : super.pipe(); + } + } export const StatefulEvt: { diff --git a/deno_dist/lib/types/interfaces/StatefulReadonlyEvt.ts b/deno_dist/lib/types/interfaces/StatefulReadonlyEvt.ts index 89c83b25..6f02df37 100644 --- a/deno_dist/lib/types/interfaces/StatefulReadonlyEvt.ts +++ b/deno_dist/lib/types/interfaces/StatefulReadonlyEvt.ts @@ -4,11 +4,15 @@ import { Operator } from "../Operator.ts"; type NonPostableEvt = import("./NonPostableEvt.ts").NonPostableEvt; type CtxLike = import("./CtxLike.ts").CtxLike; type StatefulEvt = import("./StatefulEvt.ts").StatefulEvt; +type Evt = import("./Evt.ts").Evt; export type StateDiff = { prevState: T, newState: T }; export interface StatefulReadonlyEvt extends NonPostableEvt { + /** https://docs.evt.land/api/statefulevt#converting-an-evt-into-a-statefulevt */ + toStateless(ctx?: CtxLike): Evt; + readonly state: T; /** https://docs.evt.land/api/statefulevt#evtdiff */ @@ -20,93 +24,94 @@ export interface StatefulReadonlyEvt extends NonPostableEvt { /** https://docs.evt.land/api/statefulevt#evtchangediff */ readonly evtChangeDiff: NonPostableEvt>; + //TODO: update docs. /** https://docs.evt.land/api/statefulevt#statefulpipe */ - statefulPipe(): StatefulEvt; + pipe(): StatefulEvt; - statefulPipe( + pipe( op: Operator.fλ ): StatefulEvt; - statefulPipe( + pipe( op: (data: T) => data is U ): StatefulEvt; - statefulPipe( + pipe( op: (data: T) => boolean ): StatefulEvt; - statefulPipe(ctx: CtxLike): StatefulEvt; + pipe(ctx: CtxLike): StatefulEvt; - statefulPipe( + pipe( ctx: CtxLike, op: Operator.fλ ): StatefulEvt; - statefulPipe( + pipe( ctx: CtxLike, op: (data: T) => data is U ): StatefulEvt; - statefulPipe( + pipe( ctx: CtxLike, op: (data: T) => boolean ): StatefulEvt; - statefulPipe( + pipe( op1: Operator.fλ, op2: Operator.fλ ): StatefulEvt; - statefulPipe( + pipe( op1: Operator.fλ, op2: (data: B) => data is C ): StatefulEvt; - statefulPipe( + pipe( op1: Operator.fλ, op2: (data: B) => boolean ): StatefulEvt; - statefulPipe( + pipe( op1: (data: T) => data is B, op2: Operator.fλ ): StatefulEvt; - statefulPipe( + pipe( op1: (data: T) => boolean, op2: Operator.fλ ): StatefulEvt; - statefulPipe( + pipe( op1: (data: T) => data is B, op2: (data: B) => data is C ): StatefulEvt; - statefulPipe( + pipe( op1: (data: T) => data is B, op2: (data: B) => boolean ): StatefulEvt; - statefulPipe( + pipe( op1: (data: T) => boolean, op2: (data: T) => data is B ): StatefulEvt; - statefulPipe( + pipe( op1: (data: T) => boolean, op2: (data: T) => boolean ): StatefulEvt; - statefulPipe( + pipe( op1: Operator.fλ, op2: Operator.fλ, op3: Operator.fλ ): StatefulEvt; - statefulPipe( + pipe( op1: Operator.fλ, op2: Operator.fλ, op3: Operator.fλ, op4: Operator.fλ ): StatefulEvt; - statefulPipe( + pipe( op1: Operator.fλ, op2: Operator.fλ, op3: Operator.fλ, op4: Operator.fλ ): StatefulEvt; - statefulPipe( + pipe( op1: Operator.fλ, op2: Operator.fλ, op3: Operator.fλ, @@ -115,25 +120,25 @@ export interface StatefulReadonlyEvt extends NonPostableEvt { ): StatefulEvt; - statefulPipe( + pipe( op1: Operator, op2: Operator ): StatefulEvt; - statefulPipe( + pipe( op1: Operator, op2: Operator, op3: Operator ): StatefulEvt; - statefulPipe( + pipe( op1: Operator, op2: Operator, op3: Operator, op4: Operator ): StatefulEvt; - statefulPipe( + pipe( op1: Operator, op2: Operator, op3: Operator, @@ -141,14 +146,14 @@ export interface StatefulReadonlyEvt extends NonPostableEvt { op5: Operator ): StatefulEvt; - statefulPipe( + pipe( ...ops: [ Operator, ...Operator[] ] ): StatefulEvt; - statefulPipe( + pipe( ...ops: [ Operator, ...Operator[] diff --git a/deno_dist/test/deno_index.ts b/deno_dist/test/deno_index.ts index 08055f29..9361aeed 100644 --- a/deno_dist/test/deno_index.ts +++ b/deno_dist/test/deno_index.ts @@ -90,4 +90,5 @@ import "./test85.ts"; import "./test86.ts"; import "./test87.ts"; import "./test88.ts"; -import "./test89.ts"; \ No newline at end of file +import "./test89.ts"; +import "./test90.ts"; \ No newline at end of file diff --git a/deno_dist/test/index.ts b/deno_dist/test/index.ts index 08ec766b..d2044578 100644 --- a/deno_dist/test/index.ts +++ b/deno_dist/test/index.ts @@ -31,7 +31,7 @@ if (n) { await new Promise(resolve => setTimeout(resolve, 2400)); - const n = 89; + const n = 90; console.log({ n }); diff --git a/deno_dist/test/test73.ts b/deno_dist/test/test73.ts index a65cfe0c..23caaf96 100644 --- a/deno_dist/test/test73.ts +++ b/deno_dist/test/test73.ts @@ -8,7 +8,7 @@ import { assert } from "../tools/typeSafety/assert.ts"; const sevText = Evt.create("foo"); - const sevCharCount = sevText.statefulPipe(text => [text.length]); + const sevCharCount = sevText.pipe(text => [text.length]); assert(sevCharCount.state === sevText.state.length); @@ -24,7 +24,7 @@ import { assert } from "../tools/typeSafety/assert.ts"; const sevText = Evt.create("foo"); - const sevCharCount = sevText.statefulPipe(ctx, text => [text.length]); + const sevCharCount = sevText.pipe(ctx, text => [text.length]); assert(sevCharCount.state === sevText.state.length); @@ -97,7 +97,7 @@ import { assert } from "../tools/typeSafety/assert.ts"; const sevText = Evt.create("foo"); - const sevCharCount = sevText.statefulPipe(text => [text.length]); + const sevCharCount = sevText.pipe(text => [text.length]); assert(sevCharCount.state === sevText.state.length); @@ -113,7 +113,7 @@ import { assert } from "../tools/typeSafety/assert.ts"; const sevText = Evt.create("foo"); - const sevCharCount = sevText.statefulPipe(ctx, text => [text.length]); + const sevCharCount = sevText.pipe(ctx, text => [text.length]); assert(sevCharCount.state === sevText.state.length); diff --git a/deno_dist/test/test87.ts b/deno_dist/test/test87.ts index 2be1efa4..cd0ad9b5 100644 --- a/deno_dist/test/test87.ts +++ b/deno_dist/test/test87.ts @@ -9,8 +9,8 @@ const evtIsBigAndBlue = Evt.merge([ evtIsBlue.evtChange, evtIsBig.evtChange ]) - .toStateful() //It is safe to use as any here - .statefulPipe(()=> [ evtIsBlue.state && evtIsBig.state ]) + .toStateful() + .pipe(()=> [ evtIsBlue.state && evtIsBig.state ]) ; assert(evtIsBigAndBlue.state === false as boolean); diff --git a/deno_dist/test/test89.ts b/deno_dist/test/test89.ts index e015e1f6..992da05f 100644 --- a/deno_dist/test/test89.ts +++ b/deno_dist/test/test89.ts @@ -12,7 +12,7 @@ const ctx = Evt.newCtx(); Evt.useEffect( text => std_out+= text.toString(), - evtText.evtChange.statefulPipe(ctx) + evtText.evtChange.pipe(ctx) ); assert( std_out === "foo" as string); diff --git a/deno_dist/test/test90.ts b/deno_dist/test/test90.ts new file mode 100644 index 00000000..b6698aa9 --- /dev/null +++ b/deno_dist/test/test90.ts @@ -0,0 +1,40 @@ + +import { Evt } from "../lib/index.ts"; +import { assert } from "../tools/typeSafety/index.ts"; + +const evtText = Evt.create("foo"); + +try { + + evtText.pipe(text => text.startsWith("f") ? null : [text.toUpperCase()]); + + assert(false); + +} catch{ } + +const ctx = Evt.newCtx(); + +const evtTextSt = evtText.toStateless(ctx) + .pipe(text => text.startsWith("f") ? null : [text.toUpperCase()]) + .toStateful() + ; + + +assert(evtTextSt.state === undefined as any); + +evtText.post("foobar"); + +assert(evtTextSt.state === undefined as any); + +evtText.post("baz"); + +assert(evtTextSt.state === "BAZ" as any); + +ctx.done(); + +evtText.post("hello"); + +assert(evtTextSt.state === "BAZ" as any); + +console.log("PASS"); + diff --git a/dist/lib/StatefulEvt.js b/dist/lib/StatefulEvt.js index 03514fd0..6fe0c7b1 100644 --- a/dist/lib/StatefulEvt.js +++ b/dist/lib/StatefulEvt.js @@ -69,23 +69,27 @@ var StatefulEvtImpl = /** @class */ (function (_super) { } return _super.prototype.post.call(this, data); }; - StatefulEvtImpl.prototype.statefulPipe = function () { + StatefulEvtImpl.prototype.pipe = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } - var evt = this - .pipe.apply(this, __spread(args)); + var evt = _super.prototype.pipe.apply(this, __spread(args)); var opResult = invokeOperator_1.invokeOperator(this.getStatelessOp(Evt_parsePropsFromArgs_1.parsePropsFromArgs(args, "pipe").op), this.state); if (Operator_1.Operator.fλ.Result.NotMatched.match(opResult)) { throw new Error([ - "Operator do not match current state", - "use evt.pipe([ctx], op).toStatic(initialState)", + "Cannot pipe StatefulEvt because the operator does not match", + "it's current state.", + "Use evt.toStateless([ctx]).pipe(op).toStatic(initialState)", "to be sure the StatefulEvt is correctly initialized" ].join(" ")); } return evt.toStateful(opResult[0]); }; + /** Return a stateless copy */ + StatefulEvtImpl.prototype.toStateless = function (ctx) { + return !!ctx ? _super.prototype.pipe.call(this, ctx) : _super.prototype.pipe.call(this); + }; StatefulEvtImpl.__4 = (function () { if (false) { StatefulEvtImpl.__4; diff --git a/dist/lib/StatefulEvt.js.map b/dist/lib/StatefulEvt.js.map index 794fba0d..afd1508a 100644 --- a/dist/lib/StatefulEvt.js.map +++ b/dist/lib/StatefulEvt.js.map @@ -1 +1 @@ -{"version":3,"file":"StatefulEvt.js","sourceRoot":"","sources":["../../src/lib/StatefulEvt.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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/dist/lib/types/interfaces/StatefulReadonlyEvt.d.ts index 861b1e7b..bf968f5e 100644 --- a/dist/lib/types/interfaces/StatefulReadonlyEvt.d.ts +++ b/dist/lib/types/interfaces/StatefulReadonlyEvt.d.ts @@ -2,11 +2,14 @@ import { Operator } from "../Operator"; declare type NonPostableEvt = import("./NonPostableEvt").NonPostableEvt; declare type CtxLike = import("./CtxLike").CtxLike; declare type StatefulEvt = import("./StatefulEvt").StatefulEvt; +declare type Evt = import("./Evt").Evt; export declare type StateDiff = { prevState: T; newState: T; }; export interface StatefulReadonlyEvt extends NonPostableEvt { + /** https://docs.evt.land/api/statefulevt#converting-an-evt-into-a-statefulevt */ + toStateless(ctx?: CtxLike): Evt; readonly state: T; /** https://docs.evt.land/api/statefulevt#evtdiff */ readonly evtDiff: NonPostableEvt>; @@ -15,32 +18,32 @@ export interface StatefulReadonlyEvt extends NonPostableEvt { /** https://docs.evt.land/api/statefulevt#evtchangediff */ readonly evtChangeDiff: NonPostableEvt>; /** https://docs.evt.land/api/statefulevt#statefulpipe */ - statefulPipe(): StatefulEvt; - statefulPipe(op: Operator.fλ): StatefulEvt; - statefulPipe(op: (data: T) => data is U): StatefulEvt; - statefulPipe(op: (data: T) => boolean): StatefulEvt; - statefulPipe(ctx: CtxLike): StatefulEvt; - statefulPipe(ctx: CtxLike, op: Operator.fλ): StatefulEvt; - statefulPipe(ctx: CtxLike, op: (data: T) => data is U): StatefulEvt; - statefulPipe(ctx: CtxLike, op: (data: T) => boolean): StatefulEvt; - statefulPipe(op1: Operator.fλ, op2: Operator.fλ): StatefulEvt; - statefulPipe(op1: Operator.fλ, op2: (data: B) => data is C): StatefulEvt; - statefulPipe(op1: Operator.fλ, op2: (data: B) => boolean): StatefulEvt; - statefulPipe(op1: (data: T) => data is B, op2: Operator.fλ): StatefulEvt; - statefulPipe(op1: (data: T) => boolean, op2: Operator.fλ): StatefulEvt; - statefulPipe(op1: (data: T) => data is B, op2: (data: B) => data is C): StatefulEvt; - statefulPipe(op1: (data: T) => data is B, op2: (data: B) => boolean): StatefulEvt; - statefulPipe(op1: (data: T) => boolean, op2: (data: T) => data is B): StatefulEvt; - statefulPipe(op1: (data: T) => boolean, op2: (data: T) => boolean): StatefulEvt; - statefulPipe(op1: Operator.fλ, op2: Operator.fλ, op3: Operator.fλ): StatefulEvt; - statefulPipe(op1: Operator.fλ, op2: Operator.fλ, op3: Operator.fλ, op4: Operator.fλ): StatefulEvt; - statefulPipe(op1: Operator.fλ, op2: Operator.fλ, op3: Operator.fλ, op4: Operator.fλ): StatefulEvt; - statefulPipe(op1: Operator.fλ, op2: Operator.fλ, op3: Operator.fλ, op4: Operator.fλ, op5: Operator.fλ): StatefulEvt; - statefulPipe(op1: Operator, op2: Operator): StatefulEvt; - statefulPipe(op1: Operator, op2: Operator, op3: Operator): StatefulEvt; - statefulPipe(op1: Operator, op2: Operator, op3: Operator, op4: Operator): StatefulEvt; - statefulPipe(op1: Operator, op2: Operator, op3: Operator, op4: Operator, op5: Operator): StatefulEvt; - statefulPipe(...ops: [Operator, ...Operator[]]): StatefulEvt; - statefulPipe(...ops: [Operator, ...Operator[]]): StatefulEvt; + pipe(): StatefulEvt; + pipe(op: Operator.fλ): StatefulEvt; + pipe(op: (data: T) => data is U): StatefulEvt; + pipe(op: (data: T) => boolean): StatefulEvt; + pipe(ctx: CtxLike): StatefulEvt; + pipe(ctx: CtxLike, op: Operator.fλ): StatefulEvt; + pipe(ctx: CtxLike, op: (data: T) => data is U): StatefulEvt; + pipe(ctx: CtxLike, op: (data: T) => boolean): StatefulEvt; + pipe(op1: Operator.fλ, op2: Operator.fλ): StatefulEvt; + pipe(op1: Operator.fλ, op2: (data: B) => data is C): StatefulEvt; + pipe(op1: Operator.fλ, op2: (data: B) => boolean): StatefulEvt; + pipe(op1: (data: T) => data is B, op2: Operator.fλ): StatefulEvt; + pipe(op1: (data: T) => boolean, op2: Operator.fλ): StatefulEvt; + pipe(op1: (data: T) => data is B, op2: (data: B) => data is C): StatefulEvt; + pipe(op1: (data: T) => data is B, op2: (data: B) => boolean): StatefulEvt; + pipe(op1: (data: T) => boolean, op2: (data: T) => data is B): StatefulEvt; + pipe(op1: (data: T) => boolean, op2: (data: T) => boolean): StatefulEvt; + pipe(op1: Operator.fλ, op2: Operator.fλ, op3: Operator.fλ): StatefulEvt; + pipe(op1: Operator.fλ, op2: Operator.fλ, op3: Operator.fλ, op4: Operator.fλ): StatefulEvt; + pipe(op1: Operator.fλ, op2: Operator.fλ, op3: Operator.fλ, op4: Operator.fλ): StatefulEvt; + pipe(op1: Operator.fλ, op2: Operator.fλ, op3: Operator.fλ, op4: Operator.fλ, op5: Operator.fλ): StatefulEvt; + pipe(op1: Operator, op2: Operator): StatefulEvt; + pipe(op1: Operator, op2: Operator, op3: Operator): StatefulEvt; + pipe(op1: Operator, op2: Operator, op3: Operator, op4: Operator): StatefulEvt; + pipe(op1: Operator, op2: Operator, op3: Operator, op4: Operator, op5: Operator): StatefulEvt; + pipe(...ops: [Operator, ...Operator[]]): StatefulEvt; + pipe(...ops: [Operator, ...Operator[]]): StatefulEvt; } export {}; diff --git a/dist/tsconfig.tsbuildinfo b/dist/tsconfig.tsbuildinfo index 2e2a3ccb..c10e1613 100644 --- a/dist/tsconfig.tsbuildinfo +++ b/dist/tsconfig.tsbuildinfo @@ -154,8 +154,8 @@ "signature": "56040fac2784c73bdb749cad83d380b1fa0f5e545f10a3a264e0fedf38d0f8cc" }, "../src/lib/types/interfaces/statefulreadonlyevt.ts": { - "version": "231bca7d17fca83eb211e3405457dc20afd59629afbf105e0eb918833fd516cc", - "signature": "b0f09fa780a6b6610f07dc6f5a8abfe7148fe821b1d86d36dc73a0a03989e5fb" + "version": "c2003519920ce9b2e8a29f83d34592ca766ea0dda4503c71c5f84487a20e7866", + "signature": "f2a8884060ed89b52cf8fa575bc39ce14e27765d0f8c9c8a5e493133826dfd13" }, "../src/lib/types/interfaces/statefulpostable.ts": { "version": "4988fbbe057ec061a5e8a7f4b9f9230471cff13607c825b28323fca641c1e5af", @@ -302,7 +302,7 @@ "signature": "deab4c2ecafe68d2b12f97ed18961a614734ee1eb2af3008bad1d1924a03c836" }, "../src/lib/statefulevt.ts": { - "version": "0f3d3ea85d4a1397145f74bcf3a493f27577a9e8bfc8b746dcabf2c4bf6bd611", + "version": "4d27160245453a6f7ca8452a720d339292a664dc09c33943fba4963b95aa4dc0", "signature": "a607bf14aa9b8e6322dc9b9112e27e9d2fcdfe7bd8e664d0d1a249fb31d100ec" }, "../src/lib/importproxy.ts": { @@ -666,7 +666,7 @@ "signature": "8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881" }, "../src/test/test73.ts": { - "version": "b065e074f96992c466ec0d85e9cb013178ef12b4c0c1600301b4de9319637411", + "version": "48d41f22a3fda70f4780a19b0f4468cefa4d71fe35e2c99d214d4239c9137837", "signature": "8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881" }, "../src/test/test76.ts": { @@ -710,7 +710,7 @@ "signature": "8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881" }, "../src/test/test87.ts": { - "version": "cc1de6365d5cb2ccb742ec14b3138f370bfc725096a985436b1baf6c4ca31622", + "version": "f7d8f103a22de41461e3509e7cf5f43773ddd91e9217307e09b2bd2ebd156bde", "signature": "8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881" }, "../src/test/test88.ts": { @@ -718,15 +718,19 @@ "signature": "8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881" }, "../src/test/test89.ts": { - "version": "481d77fc4c49d960a67087b169bf28894316cfff844dd5cf72f1adf84728cddf", + "version": "1c7e38a2e9733ddb36dedc0fb69b900f579dcf95f41d5dd77b855b0659151498", + "signature": "8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881" + }, + "../src/test/test90.ts": { + "version": "4957100cf8f687303cb60280d8ed2d3ad3e356ff04cde94c1be15f9cb0a8752b", "signature": "8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881" }, "../src/test/deno_index.ts": { - "version": "adadbce38e2bb7e7244cf076b0806eed555f41a241e3bda60257fca99b6cceeb", - "signature": "63f13d1e75e59b7a44996ff569c0fd5bee73efc4c8ead8c857fda41c4ee0b988" + "version": "325e61bff2ac094eaa7b1908afcf18bf634526e6342e5b1b437fc9b3793f82a0", + "signature": "14913cef43a902c27f73756c455ab55c3efcaca3c2c4cb85a53b5b7b9c7e5522" }, "../src/test/index.ts": { - "version": "9a7a2663ef561a795d79ae5a2675efd5c7ef87b3dd69ed07804ae49028d28258", + "version": "fb55c622c18ae15e53c5b04f8b355f2f59124a1e681c9827deea0fb02c701de3", "signature": "8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881" }, "../src/test/test12.ts": { @@ -1247,6 +1251,7 @@ "../src/lib/types/interfaces/nonpostableevt.ts", "../src/lib/types/interfaces/ctxlike.ts", "../src/lib/types/interfaces/statefulevt.ts", + "../src/lib/types/interfaces/evt.ts", "../node_modules/@types/node/base.d.ts", "../node_modules/@types/node/ts3.2/index.d.ts" ], @@ -1514,6 +1519,7 @@ "../src/lib/util/invokeoperator.ts", "../src/lib/types/operator.ts", "../src/lib/evt.parsepropsfromargs.ts", + "../src/lib/types/interfaces/ctxlike.ts", "../src/lib/evt.ts", "../src/lib/types/interfaces/index.ts", "../node_modules/@types/node/base.d.ts", @@ -2171,6 +2177,12 @@ "../node_modules/@types/node/base.d.ts", "../node_modules/@types/node/ts3.2/index.d.ts" ], + "../src/test/test90.ts": [ + "../src/lib/index.ts", + "../src/tools/typesafety/index.ts", + "../node_modules/@types/node/base.d.ts", + "../node_modules/@types/node/ts3.2/index.d.ts" + ], "../src/test/deno_index.ts": [ "../src/tools/reducers/test.ts", "../src/test/test1.ts", @@ -2239,6 +2251,7 @@ "../src/test/test87.ts", "../src/test/test88.ts", "../src/test/test89.ts", + "../src/test/test90.ts", "../node_modules/@types/node/base.d.ts", "../node_modules/@types/node/ts3.2/index.d.ts" ], @@ -2893,9 +2906,10 @@ ], "../src/lib/types/interfaces/statefulreadonlyevt.ts": [ "../src/lib/types/interfaces/nonpostableevt.ts", + "../src/lib/types/interfaces/ctxlike.ts", + "../src/lib/types/interfaces/evt.ts", "../src/lib/types/interfaces/statefulevt.ts", - "../src/lib/types/operator.ts", - "../src/lib/types/interfaces/ctxlike.ts" + "../src/lib/types/operator.ts" ], "../src/lib/types/interfaces/statefulpostable.ts": [ "../src/lib/types/interfaces/postable.ts" @@ -3223,7 +3237,8 @@ "../src/test/test86.ts", "../src/test/test87.ts", "../src/test/test88.ts", - "../src/test/test89.ts" + "../src/test/test89.ts", + "../src/test/test90.ts" ], "../node_modules/rxjs/internal/subscription.d.ts": [ "../node_modules/rxjs/internal/types.d.ts", @@ -3868,6 +3883,8 @@ "../src/test/test87.ts", "../src/test/test88.ts", "../src/test/test89.ts", + "../src/test/deno_index.ts", + "../src/test/index.ts", "../src/test/test12.ts", "../src/test/test13.ts", "../src/test/test20.ts", @@ -3949,8 +3966,7 @@ "../node_modules/@types/node/inspector.d.ts", "../node_modules/@types/node/base.d.ts", "../node_modules/@types/node/ts3.2/index.d.ts", - "../src/test/deno_index.ts", - "../src/test/index.ts" + "../src/test/test90.ts" ] }, "version": "3.8.3" diff --git a/package-lock.json b/package-lock.json index 4c8a6fc7..ec698350 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "evt", - "version": "1.6.7", + "version": "1.6.8", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 26f42728..3ecf5e73 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "evt", - "version": "1.6.7", + "version": "1.6.8", "description": "Type safe replacement for node's EventEmitter", "repository": { "type": "git", diff --git a/src/lib/StatefulEvt.ts b/src/lib/StatefulEvt.ts index 6cd5c293..27eb917d 100644 --- a/src/lib/StatefulEvt.ts +++ b/src/lib/StatefulEvt.ts @@ -6,6 +6,7 @@ import { importProxy } from "./importProxy"; import { invokeOperator } from "./util/invokeOperator"; import { Operator } from "./types/Operator"; import { parsePropsFromArgs } from "./Evt.parsePropsFromArgs"; +import { CtxLike } from "./types/interfaces/CtxLike"; type Diff = import("./types/interfaces").Diff; type NonPostableEvt = import("./types/interfaces").NonPostableEvt; type StatefulReadonlyEvt= import("./types/interfaces").StatefulReadonlyEvt; @@ -94,11 +95,10 @@ class StatefulEvtImpl extends Evt implements StatefulEvt { } + pipe(...args: any[]): StatefulEvt { - statefulPipe(...args: any[]): StatefulEvt { - - const evt = this - .pipe(...(args as Parameters)) + const evt = super + .pipe(...(args as Parameters)) ; const opResult = invokeOperator( @@ -111,8 +111,9 @@ class StatefulEvtImpl extends Evt implements StatefulEvt { if (Operator.fλ.Result.NotMatched.match(opResult)) { throw new Error([ - "Operator do not match current state", - "use evt.pipe([ctx], op).toStatic(initialState)", + "Cannot pipe StatefulEvt because the operator does not match", + "it's current state.", + "Use evt.toStateless([ctx]).pipe(op).toStatic(initialState)", "to be sure the StatefulEvt is correctly initialized" ].join(" ")); @@ -122,6 +123,10 @@ class StatefulEvtImpl extends Evt implements StatefulEvt { } + toStateless(ctx?: CtxLike): Evt { + return !!ctx ? super.pipe(ctx) : super.pipe(); + } + } export const StatefulEvt: { diff --git a/src/lib/types/interfaces/StatefulReadonlyEvt.ts b/src/lib/types/interfaces/StatefulReadonlyEvt.ts index b95526a5..c3cd7794 100644 --- a/src/lib/types/interfaces/StatefulReadonlyEvt.ts +++ b/src/lib/types/interfaces/StatefulReadonlyEvt.ts @@ -4,11 +4,15 @@ import { Operator } from "../Operator"; type NonPostableEvt = import("./NonPostableEvt").NonPostableEvt; type CtxLike = import("./CtxLike").CtxLike; type StatefulEvt = import("./StatefulEvt").StatefulEvt; +type Evt = import("./Evt").Evt; export type StateDiff = { prevState: T, newState: T }; export interface StatefulReadonlyEvt extends NonPostableEvt { + /** https://docs.evt.land/api/statefulevt#tostateless-ctx */ + toStateless(ctx?: CtxLike): Evt; + readonly state: T; /** https://docs.evt.land/api/statefulevt#evtdiff */ @@ -20,93 +24,93 @@ export interface StatefulReadonlyEvt extends NonPostableEvt { /** https://docs.evt.land/api/statefulevt#evtchangediff */ readonly evtChangeDiff: NonPostableEvt>; - /** https://docs.evt.land/api/statefulevt#statefulpipe */ - statefulPipe(): StatefulEvt; + /** https://docs.evt.land/api/statefulevt#pipe */ + pipe(): StatefulEvt; - statefulPipe( + pipe( op: Operator.fλ ): StatefulEvt; - statefulPipe( + pipe( op: (data: T) => data is U ): StatefulEvt; - statefulPipe( + pipe( op: (data: T) => boolean ): StatefulEvt; - statefulPipe(ctx: CtxLike): StatefulEvt; + pipe(ctx: CtxLike): StatefulEvt; - statefulPipe( + pipe( ctx: CtxLike, op: Operator.fλ ): StatefulEvt; - statefulPipe( + pipe( ctx: CtxLike, op: (data: T) => data is U ): StatefulEvt; - statefulPipe( + pipe( ctx: CtxLike, op: (data: T) => boolean ): StatefulEvt; - statefulPipe( + pipe( op1: Operator.fλ, op2: Operator.fλ ): StatefulEvt; - statefulPipe( + pipe( op1: Operator.fλ, op2: (data: B) => data is C ): StatefulEvt; - statefulPipe( + pipe( op1: Operator.fλ, op2: (data: B) => boolean ): StatefulEvt; - statefulPipe( + pipe( op1: (data: T) => data is B, op2: Operator.fλ ): StatefulEvt; - statefulPipe( + pipe( op1: (data: T) => boolean, op2: Operator.fλ ): StatefulEvt; - statefulPipe( + pipe( op1: (data: T) => data is B, op2: (data: B) => data is C ): StatefulEvt; - statefulPipe( + pipe( op1: (data: T) => data is B, op2: (data: B) => boolean ): StatefulEvt; - statefulPipe( + pipe( op1: (data: T) => boolean, op2: (data: T) => data is B ): StatefulEvt; - statefulPipe( + pipe( op1: (data: T) => boolean, op2: (data: T) => boolean ): StatefulEvt; - statefulPipe( + pipe( op1: Operator.fλ, op2: Operator.fλ, op3: Operator.fλ ): StatefulEvt; - statefulPipe( + pipe( op1: Operator.fλ, op2: Operator.fλ, op3: Operator.fλ, op4: Operator.fλ ): StatefulEvt; - statefulPipe( + pipe( op1: Operator.fλ, op2: Operator.fλ, op3: Operator.fλ, op4: Operator.fλ ): StatefulEvt; - statefulPipe( + pipe( op1: Operator.fλ, op2: Operator.fλ, op3: Operator.fλ, @@ -115,25 +119,25 @@ export interface StatefulReadonlyEvt extends NonPostableEvt { ): StatefulEvt; - statefulPipe( + pipe( op1: Operator, op2: Operator ): StatefulEvt; - statefulPipe( + pipe( op1: Operator, op2: Operator, op3: Operator ): StatefulEvt; - statefulPipe( + pipe( op1: Operator, op2: Operator, op3: Operator, op4: Operator ): StatefulEvt; - statefulPipe( + pipe( op1: Operator, op2: Operator, op3: Operator, @@ -141,14 +145,14 @@ export interface StatefulReadonlyEvt extends NonPostableEvt { op5: Operator ): StatefulEvt; - statefulPipe( + pipe( ...ops: [ Operator, ...Operator[] ] ): StatefulEvt; - statefulPipe( + pipe( ...ops: [ Operator, ...Operator[] diff --git a/src/test/deno_index.ts b/src/test/deno_index.ts index 1902ca28..b8a01295 100644 --- a/src/test/deno_index.ts +++ b/src/test/deno_index.ts @@ -90,4 +90,5 @@ import "./test85"; import "./test86"; import "./test87"; import "./test88"; -import "./test89"; \ No newline at end of file +import "./test89"; +import "./test90"; \ No newline at end of file diff --git a/src/test/index.ts b/src/test/index.ts index c95c3442..43b40569 100644 --- a/src/test/index.ts +++ b/src/test/index.ts @@ -31,7 +31,7 @@ if (n) { await new Promise(resolve => setTimeout(resolve, 2400)); - const n = 89; + const n = 90; console.log({ n }); diff --git a/src/test/test73.ts b/src/test/test73.ts index 90d8bcb5..4887e844 100644 --- a/src/test/test73.ts +++ b/src/test/test73.ts @@ -8,7 +8,7 @@ import { assert } from "../tools/typeSafety/assert"; const sevText = Evt.create("foo"); - const sevCharCount = sevText.statefulPipe(text => [text.length]); + const sevCharCount = sevText.pipe(text => [text.length]); assert(sevCharCount.state === sevText.state.length); @@ -24,7 +24,7 @@ import { assert } from "../tools/typeSafety/assert"; const sevText = Evt.create("foo"); - const sevCharCount = sevText.statefulPipe(ctx, text => [text.length]); + const sevCharCount = sevText.pipe(ctx, text => [text.length]); assert(sevCharCount.state === sevText.state.length); @@ -97,7 +97,7 @@ import { assert } from "../tools/typeSafety/assert"; const sevText = Evt.create("foo"); - const sevCharCount = sevText.statefulPipe(text => [text.length]); + const sevCharCount = sevText.pipe(text => [text.length]); assert(sevCharCount.state === sevText.state.length); @@ -113,7 +113,7 @@ import { assert } from "../tools/typeSafety/assert"; const sevText = Evt.create("foo"); - const sevCharCount = sevText.statefulPipe(ctx, text => [text.length]); + const sevCharCount = sevText.pipe(ctx, text => [text.length]); assert(sevCharCount.state === sevText.state.length); diff --git a/src/test/test87.ts b/src/test/test87.ts index ec57a48f..36039d9f 100644 --- a/src/test/test87.ts +++ b/src/test/test87.ts @@ -9,8 +9,8 @@ const evtIsBigAndBlue = Evt.merge([ evtIsBlue.evtChange, evtIsBig.evtChange ]) - .toStateful() //It is safe to use as any here - .statefulPipe(()=> [ evtIsBlue.state && evtIsBig.state ]) + .toStateful() + .pipe(()=> [ evtIsBlue.state && evtIsBig.state ]) ; assert(evtIsBigAndBlue.state === false as boolean); diff --git a/src/test/test89.ts b/src/test/test89.ts index 9b45249e..a14a41da 100644 --- a/src/test/test89.ts +++ b/src/test/test89.ts @@ -12,7 +12,7 @@ const ctx = Evt.newCtx(); Evt.useEffect( text => std_out+= text.toString(), - evtText.evtChange.statefulPipe(ctx) + evtText.evtChange.pipe(ctx) ); assert( std_out === "foo" as string); diff --git a/src/test/test90.ts b/src/test/test90.ts new file mode 100644 index 00000000..a7f4a517 --- /dev/null +++ b/src/test/test90.ts @@ -0,0 +1,40 @@ + +import { Evt } from "../lib"; +import { assert } from "../tools/typeSafety"; + +const evtText = Evt.create("foo"); + +try { + + evtText.pipe(text => text.startsWith("f") ? null : [text.toUpperCase()]); + + assert(false); + +} catch{ } + +const ctx = Evt.newCtx(); + +const evtTextSt = evtText.toStateless(ctx) + .pipe(text => text.startsWith("f") ? null : [text.toUpperCase()]) + .toStateful() + ; + + +assert(evtTextSt.state === undefined as any); + +evtText.post("foobar"); + +assert(evtTextSt.state === undefined as any); + +evtText.post("baz"); + +assert(evtTextSt.state === "BAZ" as any); + +ctx.done(); + +evtText.post("hello"); + +assert(evtTextSt.state === "BAZ" as any); + +console.log("PASS"); +