Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typings for on() method callback #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "client-side-event-bus",
"version": "0.4.3",
"description": "A tiny and fast event bus with AMQP and Postal.js-like functionality",
"main": "index.min.js",
"main": "src/index.js",
"repository": "https://github.com/TakenPilot/client-side-event-bus.git",
"scripts": {
"build": "uglifyjs --compress --mangle --output index.min.js -- src/index.js",
Expand Down Expand Up @@ -44,7 +44,7 @@
},
"files": [
"src/index.d.ts",
"index.min.js"
"src/index.js"
],
"types": "src/index.d.ts",
"dependencies": {},
Expand Down
9 changes: 8 additions & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ export as namespace Bus;
// it's a class that can be imported
export = Bus;

interface Meta {
topic: string;
ts: Date;
}

type Callback = (message: any, meta: Meta) => void;

declare class Bus implements ClientSideEventBus {
constructor();

on(topicStr: string, fn: () => void): () => void;
on(topicStr: string, fn: Callback): () => void;
emit(topicStr: string, message?: any): Promise<any>[];
history(topicStr: string): Record<string, number>[]
}
Expand Down