MCPcopy Create free account
hub / github.com/andywer/threads.js / Subject

Class Subject

src/observable.ts:15–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13 * expose the `next()`, `error()`, `complete()` methods.
14 */
15export class Subject<T> extends Observable<T> implements ObservableLike<T> {
16 private [$observers]: Array<SubscriptionObserver<T>>
17
18 constructor() {
19 super(observer => {
20 this[$observers] = [
21 ...(this[$observers] || []),
22 observer
23 ]
24 const unsubscribe = () => {
25 this[$observers] = this[$observers].filter(someObserver => someObserver !== observer)
26 }
27 return unsubscribe
28 })
29
30 this[$observers] = []
31 }
32
33 public complete() {
34 this[$observers].forEach(observer => observer.complete())
35 }
36
37 public error(error: any) {
38 this[$observers].forEach(observer => observer.error(error))
39 }
40
41 public next(value: T) {
42 this[$observers].forEach(observer => observer.next(value))
43 }
44}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected