-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve types and get rid of @@observable nonsense
- Loading branch information
Showing
9 changed files
with
87 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (C) 2018 Klaus Reimer <[email protected]> | ||
* See LICENSE.md for licensing information. | ||
*/ | ||
|
||
import type { Observer } from "./Observer.js"; | ||
|
||
/** | ||
* Subscriber arguments. | ||
*/ | ||
export type SubscribeArgs<T = unknown> = | ||
| [ Observer<T> ] | ||
| [ (value: T) => void, ((error: Error) => void)?, (() => void)? ] | ||
| [ | ||
(((value: T) => void) | null | undefined), | ||
(((error: any) => void) | null | undefined)?, | ||
((() => void) | null | undefined)? | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (C) 2025 Klaus Reimer <[email protected]> | ||
* See LICENSE.md for licensing information. | ||
*/ | ||
|
||
import "symbol-observable"; | ||
|
||
import { from, merge, Subject } from "rxjs"; | ||
import { describe, expect, it } from "vitest"; | ||
|
||
import { Observable } from "../main/Observable.js"; | ||
import type { ObservableLike } from "../main/ObservableLike.js"; | ||
import type { SubscriptionObserver } from "../main/SubscriptionObserver.js"; | ||
|
||
describe("ObservableLike", () => { | ||
it("can be converted into RxJS observable", () => { | ||
let exposedObserver: SubscriptionObserver<number> | undefined; | ||
const observable: ObservableLike<number> = new Observable<number>(observer => { | ||
exposedObserver = observer; | ||
}); | ||
const rxjsObservable = from(observable); | ||
const values: number[] = []; | ||
rxjsObservable.subscribe(value => values.push(value)); | ||
if (exposedObserver == null) { | ||
throw new Error("Observer not exposed"); | ||
} | ||
exposedObserver.next(1); | ||
expect(values).toEqual([ 1 ]); | ||
exposedObserver.next(2); | ||
expect(values).toEqual([ 1, 2 ]); | ||
}); | ||
it("can be used in RxJS operators", () => { | ||
let exposedObserver: SubscriptionObserver<number> | undefined; | ||
const observable: ObservableLike<number> = new Observable<number>(observer => { | ||
exposedObserver = observer; | ||
}); | ||
const subject = new Subject<number>(); | ||
const mergedObservable = merge(subject, observable); | ||
const values: number[] = []; | ||
mergedObservable.subscribe(value => values.push(value)); | ||
if (exposedObserver == null) { | ||
throw new Error("Observer not exposed"); | ||
} | ||
exposedObserver.next(1); | ||
subject.next(2); | ||
expect(values).toEqual([ 1, 2 ]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters