Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Reverse EventCallback state$ and inputs$ order
  • Loading branch information
OBe95 committed Dec 10, 2019
commit d8eb483fcc5d6b6c6279ebe7be9e88adf06e67fd
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ 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>,
inputs$: Observable<RestrictArray<Inputs>>,
) => Observable<State>

declare function useEventCallback<EventValue, State = void>(
Expand Down Expand Up @@ -335,7 +335,7 @@ import "./styles.css";
function App() {
const [count, setCount] = useState(0);
const [clickCallback, [description, x, y, prevDesc]] = useEventCallback(
(event$, inputs$, state$) =>
(event$, state$, inputs$) =>
event$.pipe(
map(event => [event.target.innerHTML, event.clientX, event.clientY]),
combineLatest(inputs$),
Expand Down
2 changes: 1 addition & 1 deletion src/__test__/use-event-callback.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ describe('useEventCallback specs', () => {
const timeToDelay = 200
const factory = (
event$: Observable<React.MouseEvent<HTMLButtonElement>>,
inputs$: Observable<number[]>,
_state$: Observable<number>,
inputs$: Observable<number[]>,
): Observable<number> =>
event$.pipe(
combineLatest(inputs$),
Expand Down
4 changes: 2 additions & 2 deletions src/use-event-callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export type EventCallback<EventValue, State, Inputs> = Not<
Inputs extends void ? true : false,
(
eventSource$: Observable<EventValue>,
inputs$: Observable<RestrictArray<Inputs>>,
state$: Observable<State>,
inputs$: Observable<RestrictArray<Inputs>>,
) => Observable<State>,
(eventSource$: Observable<EventValue>, state$: Observable<State>) => Observable<State>
>
Expand Down Expand Up @@ -67,7 +67,7 @@ export function useEventCallback<EventValue, State = void, Inputs = void>(
if (!inputs) {
value$ = (callback as EventCallback<EventValue, State, void>)(event$, state$ as Observable<State>)
} else {
value$ = (callback as any)(event$, inputs$ as Observable<Inputs>, state$ as Observable<State>)
value$ = (callback as any)(event$, state$ as Observable<State>, inputs$ as Observable<Inputs>)
}
const subscription = value$.subscribe((value) => {
state$.next(value)
Expand Down