Skip to content

Commit

Permalink
feat(rstream): update PubSub
Browse files Browse the repository at this point in the history
- update PubSub generics
- update .subscribeTopic() opts to use `TransformableOpts`
  • Loading branch information
postspectacular committed Mar 6, 2021
1 parent 0c7cc2d commit fa87168
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions packages/rstream/src/pubsub.ts
Expand Up @@ -4,10 +4,10 @@ import { unsupported } from "@thi.ng/errors";
import type { Transducer } from "@thi.ng/transducers";
import {
CloseMode,
CommonOpts,
ISubscriber,
LOGGER,
SubscriptionOpts,
TransformableOpts,
WithErrorHandlerOpts,
} from "./api";
import { Subscription, subscription } from "./subscription";
Expand Down Expand Up @@ -62,13 +62,13 @@ export interface PubSubOpts<A, B, T> {
*
* @param opts -
*/
export const pubsub = <A, B, T = any>(opts: PubSubOpts<A, B, T>) =>
export const pubsub = <A, B = A, T = any>(opts: PubSubOpts<A, B, T>) =>
new PubSub(opts);

/**
* @see {@link pubsub} for reference & examples.
*/
export class PubSub<A, B, T = any> extends Subscription<A, B> {
export class PubSub<A, B = A, T = any> extends Subscription<A, B> {
topicfn: Fn<B, T>;
topics: EquivMap<T, Subscription<B, B>>;

Expand Down Expand Up @@ -101,23 +101,23 @@ export class PubSub<A, B, T = any> extends Subscription<A, B> {

subscribeTopic<C>(
topicID: T,
opts?: Partial<CommonOpts>
opts?: Partial<TransformableOpts<B, C>>
): Subscription<B, C>;
subscribeTopic(
subscribeTopic<C>(
topicID: T,
sub: ISubscriber<B>,
opts?: Partial<CommonOpts>
): Subscription<B, B>;
sub: ISubscriber<C>,
opts?: Partial<TransformableOpts<B, C>>
): Subscription<B, C>;
subscribeTopic(
topicID: T,
sub: any,
opts?: Partial<CommonOpts>
opts?: Partial<TransformableOpts<any, any>>
): Subscription<any, any> {
let t = this.topics.get(topicID);
!t &&
this.topics.set(
topicID,
(t = subscription<B, B>(undefined, {
(t = subscription(undefined, {
closeOut: CloseMode.NEVER,
}))
);
Expand Down

0 comments on commit fa87168

Please sign in to comment.