Skip to content

Commit

Permalink
chore(typescript): update [email protected] and use tuple for combineE…
Browse files Browse the repository at this point in the history
…vents
  • Loading branch information
highfivedenis committed Oct 10, 2018
1 parent 8547a90 commit 0f5fa69
Show file tree
Hide file tree
Showing 4 changed files with 556 additions and 109 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ For instance, one could connect two node processes over WebSocket:
// firstModule.EventBus.ts
import { createEventBus } from 'ts-event-bus'
import MyEvents from './MyEvents.ts'
import MyBasicWebSocketChannel from './MyBasicWebSocketChannel.ts'
import MyBasicWebSocketClientChannel from './MyBasicWebSocketClientChannel.ts'

const EventBus = createEventBus({
events: MyEvents,
channels: [ new MyBasicWebSocketChannel('ws://your_host') ]
channels: [ new MyBasicWebSocketClientChannel('ws://your_host') ]
})

export default EventBus
Expand All @@ -52,11 +52,11 @@ export default EventBus
// secondModule.EventBus.ts
import { createEventBus } from 'ts-event-bus'
import MyEvents from './MyEvents.ts'
import MyBasicWebSocketChannel from './MyBasicWebSocketChannel.ts'
import MyBasicWebSocketServerChannel from './MyBasicWebSocketServerChannel.ts'

const EventBus = createEventBus({
events: MyEvents,
channels: [ new MyBasicWebSocketChannel('ws://your_host') ]
channels: [ new MyBasicWebSocketServerChannel('ws://your_host') ]
})
```

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"ts-loader": "^3.2.0",
"tslint": "^5.6.0",
"ts-node": "^3.3.0",
"typescript": "^2.5.2",
"typescript": "^3.1.2",
"typescript-formatter": "^7.0.0",
"webpack": "^3.10.0",
"ws": "^3.3.2"
Expand Down
103 changes: 2 additions & 101 deletions src/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,108 +6,9 @@ export interface EventDeclaration {
[slotName: string]: Slot<any, any>
}

export function combineEvents<
C1 extends EventDeclaration,
C2 extends EventDeclaration,
C3 extends EventDeclaration,
C4 extends EventDeclaration,
C5 extends EventDeclaration,
C6 extends EventDeclaration,
C7 extends EventDeclaration,
C8 extends EventDeclaration,
C9 extends EventDeclaration,
C10 extends EventDeclaration,
C11 extends EventDeclaration,
C12 extends EventDeclaration,
C13 extends EventDeclaration,
C14 extends EventDeclaration,
C15 extends EventDeclaration,
C16 extends EventDeclaration,
C17 extends EventDeclaration,
C18 extends EventDeclaration,
C19 extends EventDeclaration,
C20 extends EventDeclaration,
C21 extends EventDeclaration,
C22 extends EventDeclaration,
C23 extends EventDeclaration,
C24 extends EventDeclaration
>(
c1: C1,
c2: C2,
c3?: C3,
c4?: C4,
c5?: C5,
c6?: C6,
c7?: C7,
c8?: C8,
c9?: C9,
c10?: C10,
c11?: C11,
c12?: C12,
c13?: C13,
c14?: C14,
c15?: C15,
c16?: C16,
c17?: C17,
c18?: C18,
c19?: C19,
c20?: C20,
c21?: C21,
c22?: C22,
c23?: C23,
c24?: C24
):
C1
& C2
& C3
& C4
& C5
& C6
& C7
& C8
& C9
& C10
& C11
& C12
& C13
& C14
& C15
& C16
& C17
& C18
& C19
& C20
& C21
& C22
& C23
& C24 {
export function combineEvents<C extends EventDeclaration>(...args: C[]): { [P in keyof C]: C[P] } {
// TODO: throw if event buses have duplicate events
return Object.assign({},
c1,
c2,
c3,
c4,
c5,
c6,
c7,
c8,
c9,
c10,
c11,
c12,
c13,
c14,
c15,
c16,
c17,
c18,
c19,
c20,
c21,
c22,
c23,
c24
)
return Object.assign({}, ...args)
}

export function createEventBus<C extends EventDeclaration>(args: { events: C, channels?: Channel[] }): C {
Expand Down
Loading

0 comments on commit 0f5fa69

Please sign in to comment.