Skip to content

Commit 805912b

Browse files
Typescript support (#8)
Co-authored-by: Achmad Kurnianto <[email protected]> Co-authored-by: Renée Kooi <[email protected]>
1 parent 2734d2f commit 805912b

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22
"name": "react-bus",
33
"description": "A global event emitter for react.",
44
"version": "2.0.1",
5+
"typings": "types/index.d.ts",
56
"author": "Renée Kooi <[email protected]>",
67
"bugs": {
78
"url": "https://github.com/goto-bus-stop/react-bus/issues"
89
},
910
"dependencies": {
10-
"mitt": "^1.1.3"
11+
"mitt": "^2.1.0"
1112
},
1213
"peerDependencies": {
13-
"react": ">= 16.8.0"
14+
"react": ">=17.0.0"
1415
},
1516
"devDependencies": {
17+
"@rollup/plugin-buble": "^0.21.3",
1618
"react": "^17.0.0",
1719
"react-test-renderer": "^17.0.0",
18-
"rollup": "^2.0.1",
19-
"rollup-plugin-buble": "^0.19.8",
20-
"tape": "^5.0.1"
20+
"rollup": "^2.38.0",
21+
"tape": "^5.1.1"
2122
},
2223
"homepage": "https://github.com/goto-bus-stop/react-bus#readme",
2324
"keywords": [

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import buble from 'rollup-plugin-buble'
1+
import buble from '@rollup/plugin-buble'
22

33
const meta = require('./package.json')
44

types/index.d.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React, { FC, ReactNode } from 'react';
2+
import { Emitter, EventType, Handler } from 'mitt';
3+
export declare const BusContext: React.Context<Emitter | null>;
4+
/**
5+
* Return the event emitter.
6+
*
7+
* @export
8+
* @return {*}
9+
*/
10+
export declare function useBus(): Emitter;
11+
/**
12+
* Attach an event listener to the bus while this component is mounted. Adds the listener after mount, and removes it before unmount.
13+
*
14+
* @export
15+
* @param {string} name
16+
* @param {Handler} fn
17+
*/
18+
export declare function useListener<T = any>(name: EventType, fn: Handler<T>): void;
19+
export interface ProviderProps {
20+
children?: ReactNode;
21+
}
22+
/**
23+
* Create an event emitter that will be available to all deeply nested child elements using the useBus() hook.
24+
*
25+
* @export
26+
* @param {ProviderProps} { children }
27+
* @return {*}
28+
*/
29+
export declare const Provider: FC<ProviderProps>;

0 commit comments

Comments
 (0)