Comparing version 0.1.8 to 0.1.9
@@ -5,3 +5,4 @@ import { EventEmitter2 as EventEmitter } from "eventemitter2"; | ||
type: string; | ||
}> = ((...arg: any[]) => T) & { | ||
payload: any; | ||
}> = ((payload: T["payload"]) => T) & { | ||
eventType: T["type"]; | ||
@@ -8,0 +9,0 @@ }; |
{ | ||
"name": "ts-bus", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "tsc" | ||
"build": "tsc", | ||
"test": "jest" | ||
}, | ||
@@ -19,5 +20,8 @@ "repository": { | ||
"devDependencies": { | ||
"@types/jest": "^24.0.15", | ||
"@types/react": "^16.8.19", | ||
"jest": "^24.8.0", | ||
"ts-jest": "^24.0.2", | ||
"typescript": "^3.5.1" | ||
} | ||
} |
@@ -10,8 +10,12 @@ <img src="logo.png" width="200" height="200"/> | ||
```ts | ||
import { EventBus, defineEvent } from "ts-bus"; | ||
// Define Event | ||
export const someEvent = defineEvent<{ | ||
type SomeEvent = { | ||
type: "SOME_EVENT"; | ||
payload: { url: string }; | ||
}>("SOME_EVENT"); | ||
}; | ||
export const someEvent = defineEvent<SomeEvent>("SOME_EVENT"); | ||
// Create bus | ||
@@ -46,3 +50,3 @@ const bus = new EventBus(); | ||
- Redux - conflates state management with eventing and causes complexity around async as a result. React comes with state management out of the box these days anyway. | ||
- RxJS - could make a great event bus but feels too heavy handed for use with pretty much every project. | ||
- RxJS - could make a great event bus but feels too heavy handed for use with many projects. | ||
- Node `events` - is a little too much API for what I need here. This lib actually decorates the `EventEmitter2` package. In the future I may remove it to become dependency free. | ||
@@ -168,5 +172,5 @@ | ||
## Usage with React | ||
## React extensions | ||
Included with `ts-bus` are some React hooks and helpers. | ||
Included with `ts-bus` are some React hooks and helpers that provide a bus context as well as facilitate state management within React. | ||
@@ -173,0 +177,0 @@ #### BusProvider |
238460
17
172
253
5