Skip to content

Commit

Permalink
chore: use mitt where possible (#6535)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeluard authored Mar 13, 2024
1 parent 822446f commit 1d3bf04
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 1 addition & 2 deletions packages/light-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@
"@lodestar/params": "^1.17.0",
"@lodestar/types": "^1.17.0",
"@lodestar/utils": "^1.17.0",
"mitt": "^3.0.0",
"strict-event-emitter-types": "^2.0.0"
"mitt": "^3.0.0"
},
"devDependencies": {
"@chainsafe/as-sha256": "^0.4.1",
Expand Down
12 changes: 7 additions & 5 deletions packages/light-client/src/transport/rest.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import EventEmitter from "events";
import {type StrictEventEmitter} from "strict-event-emitter-types";
import mitt from "mitt";
import {type allForks, type SyncPeriod} from "@lodestar/types";
import {type Api, ApiError, routes} from "@lodestar/api";
import {type ForkName} from "@lodestar/params";
import {MittEmitter} from "../events.js";
import {type LightClientTransport} from "./interface.js";

export type LightClientRestEvents = {
[routes.events.EventType.lightClientFinalityUpdate]: allForks.LightClientFinalityUpdate;
[routes.events.EventType.lightClientOptimisticUpdate]: allForks.LightClientOptimisticUpdate;
[routes.events.EventType.lightClientFinalityUpdate]: (update: allForks.LightClientFinalityUpdate) => void;
[routes.events.EventType.lightClientOptimisticUpdate]: (update: allForks.LightClientOptimisticUpdate) => void;
};

export type LightClientRestEmitter = MittEmitter<LightClientRestEvents>;

export class LightClientRestTransport implements LightClientTransport {
private controller = new AbortController();
private readonly eventEmitter: StrictEventEmitter<EventEmitter, LightClientRestEvents> = new EventEmitter();
private readonly eventEmitter: LightClientRestEmitter = mitt();
private subscribedEventstream = false;

constructor(private readonly api: Api) {}
Expand Down

0 comments on commit 1d3bf04

Please sign in to comment.