LeetCode-OpenSource/rxjs-hooks

why useEventCallback's inputs$ and states$ opposite to their input argument order

maple-leaf opened this issue · 5 comments

  const [onEvent] = useEventCallback((events$, x$, y$) => {
    x$.subscribe(x => console.log('x ', x)) // log: x [false]
    y$.subscribe(y => console.log('y ', y)) // log: y [0]
  }, [0], [false]);

I thinks x to be 0 and y to be false is expected, but useEventCallback give opposite result. Am I doing something wrong.

versions info:
rxjs-hooks: 0.4.3

crimx commented

But if I write something like this the EventValue generic of useEventCallback gets resolved to unknown. How to fix it?

const [onChange] = useEventCallback(
  (event$: Observable<React.MouseEvent<HTMLDivElement>>, $input) =>
    event$.pipe(
      map(e => e.type === 'mouseenter'),
      debounceTime(300),
      withLatestFrom($input),
      tap(([type , [onChange]]) => onChange(type))
    ),
  false,
  [props.onChange]
)
OBe95 commented

@Brooooooklyn I would like to PR this, however it would be a breaking change as the order should be reversed for each call that uses the 3 observables

Edit: Add PR link
PR link: Reverse EventCallback state$ and inputs$ order

Fixed in #115