@@ -59,19 +59,20 @@ class Filter extends BaseProtocol implements IFilter {
59
59
}
60
60
61
61
/**
62
- * @param decoders Array of Decoders to use to decode messages, it also specifies the content topics.
62
+ * @param decoders Decoder or array of Decoders to use to decode messages, it also specifies the content topics.
63
63
* @param callback A function that will be called on each message returned by the filter.
64
64
* @param opts The FilterSubscriptionOpts used to narrow which messages are returned, and which peer to connect to.
65
65
* @returns Unsubscribe function that can be used to end the subscription.
66
66
*/
67
67
async subscribe < T extends IDecodedMessage > (
68
- decoders : IDecoder < T > [ ] ,
68
+ decoders : IDecoder < T > | IDecoder < T > [ ] ,
69
69
callback : Callback < T > ,
70
70
opts ?: ProtocolOptions
71
71
) : Promise < UnsubscribeFunction > {
72
+ const decodersArray = Array . isArray ( decoders ) ? decoders : [ decoders ] ;
72
73
const { pubSubTopic = DefaultPubSubTopic } = this . options ;
73
74
74
- const contentTopics = Array . from ( groupByContentTopic ( decoders ) . keys ( ) ) ;
75
+ const contentTopics = Array . from ( groupByContentTopic ( decodersArray ) . keys ( ) ) ;
75
76
76
77
const contentFilters = contentTopics . map ( ( contentTopic ) => ( {
77
78
contentTopic,
@@ -110,7 +111,11 @@ class Filter extends BaseProtocol implements IFilter {
110
111
throw e ;
111
112
}
112
113
113
- const subscription : Subscription < T > = { callback, decoders, pubSubTopic } ;
114
+ const subscription : Subscription < T > = {
115
+ callback,
116
+ decoders : decodersArray ,
117
+ pubSubTopic,
118
+ } ;
114
119
this . subscriptions . set ( requestId , subscription ) ;
115
120
116
121
return async ( ) => {
0 commit comments