rzjs 0.1.0
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/index.ts +110 -0
- package/operators/debug.ts +8 -0
- package/operators/log.ts +5 -0
- package/package.json +31 -0
- package/publish2.sh +3 -0
- package/ryjs-0.1.0.tgz +0 -0
package/index.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Observable, Observer, Subject, BehaviorSubject, OperatorFunction, merge } from "rxjs";
|
|
2
|
+
|
|
3
|
+
export class Stream<I, O = I> extends Observable<O> implements Observer<I> {
|
|
4
|
+
private readonly input: Subject<I>;
|
|
5
|
+
private readonly output$: Observable<O>;
|
|
6
|
+
|
|
7
|
+
constructor();
|
|
8
|
+
constructor(initial: I);
|
|
9
|
+
constructor(initial?: I) {
|
|
10
|
+
const input =
|
|
11
|
+
arguments.length === 0
|
|
12
|
+
? new Subject<I>()
|
|
13
|
+
: new BehaviorSubject<I>(initial as I);
|
|
14
|
+
|
|
15
|
+
super(subscriber => input.subscribe(subscriber));
|
|
16
|
+
|
|
17
|
+
this.input = input;
|
|
18
|
+
this.output$ = input as unknown as Observable<O>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
private static fromInternal<I, O>(
|
|
22
|
+
input: Subject<I>,
|
|
23
|
+
output$: Observable<O>
|
|
24
|
+
): Stream<I, O> {
|
|
25
|
+
const s = Object.create(Stream.prototype) as Stream<I, O>;
|
|
26
|
+
Observable.call(s, subscriber => output$.subscribe(subscriber));
|
|
27
|
+
s.input = input;
|
|
28
|
+
s.output$ = output$;
|
|
29
|
+
return s;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
next(value: I): void {
|
|
33
|
+
this.input.next(value);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
error(err: any): void {
|
|
37
|
+
this.input.error(err);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
complete(): void {
|
|
41
|
+
this.input.complete();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// pipe: same input, transformed view
|
|
45
|
+
pipe(): Stream<I, O>;
|
|
46
|
+
pipe<A>(op1: OperatorFunction<O, A>): Stream<I, A>;
|
|
47
|
+
pipe<A, B>(
|
|
48
|
+
op1: OperatorFunction<O, A>,
|
|
49
|
+
op2: OperatorFunction<A, B>
|
|
50
|
+
): Stream<I, B>;
|
|
51
|
+
pipe<A, B, C>(
|
|
52
|
+
op1: OperatorFunction<O, A>,
|
|
53
|
+
op2: OperatorFunction<A, B>,
|
|
54
|
+
op3: OperatorFunction<B, C>
|
|
55
|
+
): Stream<I, C>;
|
|
56
|
+
pipe<A, B, C, D>(
|
|
57
|
+
op1: OperatorFunction<O, A>,
|
|
58
|
+
op2: OperatorFunction<A, B>,
|
|
59
|
+
op3: OperatorFunction<B, C>,
|
|
60
|
+
op4: OperatorFunction<C, D>
|
|
61
|
+
): Stream<I, D>;
|
|
62
|
+
pipe(...ops: OperatorFunction<any, any>[]): Stream<any, any> {
|
|
63
|
+
if (ops.length === 0) return this;
|
|
64
|
+
const out$ = this.output$.pipe(...ops);
|
|
65
|
+
return Stream.fromInternal(this.input, out$);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// tee: new input, merged downstream
|
|
69
|
+
tee(): Stream<O, O>;
|
|
70
|
+
tee<A>(op1: OperatorFunction<O, A>): Stream<O, A>;
|
|
71
|
+
tee<A, B>(
|
|
72
|
+
op1: OperatorFunction<O, A>,
|
|
73
|
+
op2: OperatorFunction<A, B>
|
|
74
|
+
): Stream<O, B>;
|
|
75
|
+
tee<A, B, C>(
|
|
76
|
+
op1: OperatorFunction<O, A>,
|
|
77
|
+
op2: OperatorFunction<A, B>,
|
|
78
|
+
op3: OperatorFunction<B, C>
|
|
79
|
+
): Stream<O, C>;
|
|
80
|
+
tee<A, B, C, D>(
|
|
81
|
+
op1: OperatorFunction<O, A>,
|
|
82
|
+
op2: OperatorFunction<A, B>,
|
|
83
|
+
op3: OperatorFunction<B, C>,
|
|
84
|
+
op4: OperatorFunction<C, D>
|
|
85
|
+
): Stream<O, D>;
|
|
86
|
+
tee(...ops: OperatorFunction<any, any>[]): Stream<any, any> {
|
|
87
|
+
const input = new Subject<any>();
|
|
88
|
+
const fromUpstream$ =
|
|
89
|
+
ops.length === 0 ? this.output$ : this.output$.pipe(...ops);
|
|
90
|
+
const fromHere$ =
|
|
91
|
+
ops.length === 0 ? input : input.pipe(...ops);
|
|
92
|
+
const out$ = merge(fromUpstream$, fromHere$);
|
|
93
|
+
return Stream.fromInternal(input, out$);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export * from "rxjs";
|
|
98
|
+
|
|
99
|
+
export { ajax } from "rxjs/ajax";
|
|
100
|
+
export type { AjaxResponse, AjaxConfig } from "rxjs/ajax";
|
|
101
|
+
|
|
102
|
+
export { webSocket } from "rxjs/webSocket";
|
|
103
|
+
|
|
104
|
+
export { log } from "./operators/log";
|
|
105
|
+
export { debug, step } from "./operators/debug";
|
|
106
|
+
|
|
107
|
+
export type {
|
|
108
|
+
WebSocketSubject,
|
|
109
|
+
WebSocketSubjectConfig
|
|
110
|
+
} from "rxjs/webSocket";
|
package/operators/log.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rzjs",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "RxJS repackaged for Stream-Oriented Programming",
|
|
5
|
+
"main": "index.ts",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "vitest"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"rxjs",
|
|
12
|
+
"rx",
|
|
13
|
+
"html",
|
|
14
|
+
"observables",
|
|
15
|
+
"observable",
|
|
16
|
+
"reactive",
|
|
17
|
+
"stream",
|
|
18
|
+
"sp",
|
|
19
|
+
"stream-oriented",
|
|
20
|
+
"stream-oriented programming",
|
|
21
|
+
"stream oriented programming"
|
|
22
|
+
],
|
|
23
|
+
"author": "D++",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"rxjs": "^7.8.1"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"vite": "^7.3.0"
|
|
30
|
+
}
|
|
31
|
+
}
|
package/publish2.sh
ADDED
package/ryjs-0.1.0.tgz
ADDED
|
Binary file
|