Skip to content
Merged
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
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,32 @@
"@types/sinon": "^7.0.6",
"@types/sinon-chai": "^3.2.2",
"@types/webpack": "^4.4.24",
"coveralls": "^3.0.2",
"coveralls": "^3.0.3",
"fork-ts-checker-webpack-plugin": "^0.5.2",
"happypack": "^5.0.1",
"html-webpack-plugin": "^3.2.0",
"husky": "^1.3.1",
"jest": "^24.1.0",
"lint-staged": "^8.1.4",
"prettier": "^1.16.4",
"react": "16.8.2",
"react-dom": "16.8.2",
"react-test-renderer": "16.8.2",
"react": "16.8.3",
"react-dom": "16.8.3",
"react-test-renderer": "16.8.3",
"rxjs": "^6.4.0",
"sinon": "^7.2.3",
"sinon": "^7.2.4",
"source-map-loader": "^0.2.4",
"standard": "^12.0.1",
"ts-jest": "^23.10.5",
"ts-jest": "^24.0.0",
"ts-loader": "^5.3.3",
"tslint": "^5.12.1",
"tslint": "^5.13.0",
"tslint-config-prettier": "^1.18.0",
"tslint-eslint-rules": "^5.4.0",
"tslint-react": "^3.6.0",
"tslint-sonarts": "^1.9.0",
"typescript": "3.1.6",
"typescript": "^3.3.3",
"webpack": "^4.29.5",
"webpack-cli": "^3.2.3",
"webpack-dev-server": "^3.1.14"
"webpack-dev-server": "^3.2.1"
},
"dependencies": {
"tslib": "^1.9.3"
Expand Down
1 change: 1 addition & 0 deletions src/type.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export type RestrictArray<T> = T extends any[] ? T : []
export type VoidAsNull<T> = T extends void ? null : T
export type Not<P, T, F> = P extends false ? T : F
18 changes: 10 additions & 8 deletions src/use-event-callback.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from 'react'
import { Observable, BehaviorSubject, Subject, noop } from 'rxjs'

import { RestrictArray, VoidAsNull } from './type'
import { RestrictArray, VoidAsNull, Not } from './type'

export type EventCallbackState<EventValue, State, Inputs = void> = [
(val: EventValue) => void,
Expand All @@ -12,13 +12,15 @@ export type ReturnedState<EventValue, State, Inputs> = [
EventCallbackState<EventValue, State, Inputs>[1][0]
]

export type EventCallback<EventValue, State, Inputs> = Inputs extends void
? (eventSource$: Observable<EventValue>, state$: Observable<State>) => Observable<State>
: (
eventSource$: Observable<EventValue>,
inputs$: Observable<RestrictArray<Inputs>>,
state$: Observable<State>,
) => Observable<State>
export type EventCallback<EventValue, State, Inputs> = Not<
Inputs extends void ? true : false,
(
eventSource$: Observable<EventValue>,
inputs$: Observable<RestrictArray<Inputs>>,
state$: Observable<State>,
) => Observable<State>,
(eventSource$: Observable<EventValue>, state$: Observable<State>) => Observable<State>
>

export function useEventCallback<EventValue>(
callback: EventCallback<EventValue, void, void>,
Expand Down
Loading