@decohere/core 0.0.1-dev.130 → 0.0.1-dev.131
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.
|
@@ -8,6 +8,7 @@ _export_star(require("./decorator.js"), exports);
|
|
|
8
8
|
_export_star(require("./environment.js"), exports);
|
|
9
9
|
_export_star(require("./function.types.js"), exports);
|
|
10
10
|
_export_star(require("./retry.decorator.js"), exports);
|
|
11
|
+
_export_star(require("./subject.js"), exports);
|
|
11
12
|
_export_star(require("./type.utils.js"), exports);
|
|
12
13
|
function _export_star(from, to) {
|
|
13
14
|
Object.keys(from).forEach(function(k) {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** A listener's handle: `unsubscribe` stops it receiving values. */ "use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "Subject", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Subject;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
class Subject {
|
|
12
|
+
#listeners = new Set();
|
|
13
|
+
subscribe(listener) {
|
|
14
|
+
// An entry per call, so the same function subscribed twice is two listeners.
|
|
15
|
+
const entry = {
|
|
16
|
+
listener
|
|
17
|
+
};
|
|
18
|
+
this.#listeners.add(entry);
|
|
19
|
+
return {
|
|
20
|
+
unsubscribe: ()=>this.#listeners.delete(entry)
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** Calls every listener; one that throws doesn't stop the rest, and its error is rethrown. */ next(value) {
|
|
24
|
+
const errors = [];
|
|
25
|
+
// A copy: a listener subscribed while this runs gets the next value, not this one.
|
|
26
|
+
for (const { listener } of Array.from(this.#listeners)){
|
|
27
|
+
try {
|
|
28
|
+
listener(value);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
errors.push(error);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (errors.length === 1) throw errors[0];
|
|
34
|
+
if (errors.length > 1) throw new AggregateError(errors, "Subject listeners threw");
|
|
35
|
+
}
|
|
36
|
+
asObservable() {
|
|
37
|
+
return {
|
|
38
|
+
subscribe: (listener)=>this.subscribe(listener)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
package/es6/src/system/index.js
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** A listener's handle: `unsubscribe` stops it receiving values. */ /**
|
|
2
|
+
* Sends each value to every current listener, synchronously and in subscription order.
|
|
3
|
+
* The part of rxjs's `Subject` the tools used, without loading rxjs on every start.
|
|
4
|
+
*/ export class Subject {
|
|
5
|
+
#listeners = new Set();
|
|
6
|
+
subscribe(listener) {
|
|
7
|
+
// An entry per call, so the same function subscribed twice is two listeners.
|
|
8
|
+
const entry = {
|
|
9
|
+
listener
|
|
10
|
+
};
|
|
11
|
+
this.#listeners.add(entry);
|
|
12
|
+
return {
|
|
13
|
+
unsubscribe: ()=>this.#listeners.delete(entry)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** Calls every listener; one that throws doesn't stop the rest, and its error is rethrown. */ next(value) {
|
|
17
|
+
const errors = [];
|
|
18
|
+
// A copy: a listener subscribed while this runs gets the next value, not this one.
|
|
19
|
+
for (const { listener } of Array.from(this.#listeners)){
|
|
20
|
+
try {
|
|
21
|
+
listener(value);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
errors.push(error);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (errors.length === 1) throw errors[0];
|
|
27
|
+
if (errors.length > 1) throw new AggregateError(errors, "Subject listeners threw");
|
|
28
|
+
}
|
|
29
|
+
asObservable() {
|
|
30
|
+
return {
|
|
31
|
+
subscribe: (listener)=>this.subscribe(listener)
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decohere/core",
|
|
3
|
-
"version": "0.0.1-dev.
|
|
3
|
+
"version": "0.0.1-dev.131",
|
|
4
4
|
"description": "The runtime base every Decohere package builds on: reflection, composition, configuration types, extensibility, collections, objects, caching on a Map, and basic file IO. No side effects on import.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@decohere/scribe": "0.0.1-dev.
|
|
77
|
+
"@decohere/scribe": "0.0.1-dev.131",
|
|
78
78
|
"reflect-metadata": "^0.2.2"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** A listener's handle: `unsubscribe` stops it receiving values. */
|
|
2
|
+
export type Subscription = {
|
|
3
|
+
unsubscribe(): void;
|
|
4
|
+
};
|
|
5
|
+
/** The listening side of a {@link Subject}: what a class exposes so callers can't emit. */
|
|
6
|
+
export type Observable<T> = {
|
|
7
|
+
subscribe(listener: (value: T) => void): Subscription;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Sends each value to every current listener, synchronously and in subscription order.
|
|
11
|
+
* The part of rxjs's `Subject` the tools used, without loading rxjs on every start.
|
|
12
|
+
*/
|
|
13
|
+
export declare class Subject<T> implements Observable<T> {
|
|
14
|
+
#private;
|
|
15
|
+
subscribe(listener: (value: T) => void): Subscription;
|
|
16
|
+
/** Calls every listener; one that throws doesn't stop the rest, and its error is rethrown. */
|
|
17
|
+
next(value: T): void;
|
|
18
|
+
asObservable(): Observable<T>;
|
|
19
|
+
}
|