How to use the observable-hooks.useObservableCallback function in observable-hooks

To help you get started, we’ve selected a few observable-hooks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github crimx / ext-saladict / src / content / components / MenuBar / SearchBox.tsx View on Github external
export const SearchBox: FC = props => {
  // Textarea also shares the text so only replace here
  const text = props.text.replace(/\s+/g, ' ')

  const [onSearchBoxFocusBlur, searchBoxFocusBlur$] = useObservableCallback(
    focusBlur
  )

  const [onSuggestFocusBlur, suggestFocusBlur$] = useObservableCallback(
    focusBlur
  )

  const [onShowSugget, onShowSugget$] = useObservableCallback(identity)

  const isShowSuggest = useObservableState(
    useObservable(
      inputs$ =>
        combineLatest(
          inputs$,
          merge(
            // only show suggest when start typing
            searchBoxFocusBlur$.pipe(filter(isFocus => !isFocus)),
            suggestFocusBlur$,
            onShowSugget$
          )
        ).pipe(
          map(([[enableSuggest, text], shouldShowSuggest]) =>
            Boolean(enableSuggest && text && shouldShowSuggest)
          ),
github crimx / ext-saladict / src / content / components / MenuBar / SearchBox.tsx View on Github external
export const SearchBox: FC = props => {
  // Textarea also shares the text so only replace here
  const text = props.text.replace(/\s+/g, ' ')

  const [onSearchBoxFocusBlur, searchBoxFocusBlur$] = useObservableCallback(
    focusBlur
  )

  const [onSuggestFocusBlur, suggestFocusBlur$] = useObservableCallback(
    focusBlur
  )

  const [onShowSugget, onShowSugget$] = useObservableCallback(identity)

  const isShowSuggest = useObservableState(
    useObservable(
      inputs$ =>
        combineLatest(
          inputs$,
          merge(
            // only show suggest when start typing
github crimx / ext-saladict / src / content / components / MenuBar / MenuBar.tsx View on Github external
export const MenuBar: FC = props => {
  const { t } = useTranslate(['content', 'common'])

  const [updateProfileHeight, profileHeight$] = useObservableCallback(
    heightChangeTransform
  )

  const [updateSBHeight, searchBoxHeight$] = useObservableCallback(
    heightChangeTransform
  )

  // update panel min height
  useSubscription(
    useObservable(() =>
      combineLatest(profileHeight$, searchBoxHeight$).pipe(
        // a little delay for organic feeling
        debounceTime(100),
        map(heights => {
          const max = Math.max(...heights)
          return max > 0 ? max + 72 : 0
        })
      )
    ),
    props.onHeightChanged
github crimx / ext-saladict / src / components / dictionaries / helpers.ts View on Github external
export const useVerticalScroll = () => {
  const [onWheel, onWHeel$] = useObservableCallback(_useVerticalScrollOnWheel)
  useSubscription(onWHeel$)

  const tabsRef = useRef(null)
  useEffect(() => {
    if (tabsRef.current) {
      // take the node out for cleaning up
      const node = tabsRef.current
      node.addEventListener('wheel', onWheel, { passive: false })
      return () => {
        node.removeEventListener('wheel', onWheel)
      }
    }
  }, [tabsRef.current])

  return tabsRef
}
github crimx / ext-saladict / src / content / components / MenuBar / Profiles.tsx View on Github external
export const Profiles: FC = props => {
  const [onMouseOverOutDelay, mouseOverOutDelay$] = useObservableCallback<
    boolean,
    React.MouseEvent<element>
  &gt;(hoverWithDelay)

  const [onMouseOverOut, mouseOverOut$] = useObservableCallback&lt;
    boolean,
    React.MouseEvent<element>
  &gt;(hover)

  const [onFocusBlur, focusBlur$] = useObservableCallback(focusBlur)

  const [showHideProfiles, showHideProfiles$] = useObservableCallback(
    identity
  )

  const isShowProfiles = useObservableState(
    useObservable(() =&gt;
      merge(mouseOverOut$, mouseOverOutDelay$, focusBlur$, showHideProfiles$)
    ).pipe(debounceTime(100)),
    false
  )

  const listItem = props.profiles.map(p =&gt; {
    return {
      key: p.id,
      content: (
        </element></element>
github crimx / ext-saladict / src / content / components / MenuBar / Profiles.tsx View on Github external
export const Profiles: FC = props =&gt; {
  const [onMouseOverOutDelay, mouseOverOutDelay$] = useObservableCallback&lt;
    boolean,
    React.MouseEvent<element>
  &gt;(hoverWithDelay)

  const [onMouseOverOut, mouseOverOut$] = useObservableCallback&lt;
    boolean,
    React.MouseEvent<element>
  &gt;(hover)

  const [onFocusBlur, focusBlur$] = useObservableCallback(focusBlur)

  const [showHideProfiles, showHideProfiles$] = useObservableCallback(
    identity
  )

  const isShowProfiles = useObservableState(
    useObservable(() =&gt;
      merge(mouseOverOut$, mouseOverOutDelay$, focusBlur$, showHideProfiles$)
    ).pipe(debounceTime(100)),
    false
  )

  const listItem = props.profiles.map(p =&gt; {
    return {
      key: p.id,
      content: (</element></element>
github crimx / ext-saladict / src / content / components / MenuBar / Profiles.tsx View on Github external
export const Profiles: FC = props =&gt; {
  const [onMouseOverOutDelay, mouseOverOutDelay$] = useObservableCallback&lt;
    boolean,
    React.MouseEvent<element>
  &gt;(hoverWithDelay)

  const [onMouseOverOut, mouseOverOut$] = useObservableCallback&lt;
    boolean,
    React.MouseEvent<element>
  &gt;(hover)

  const [onFocusBlur, focusBlur$] = useObservableCallback(focusBlur)

  const [showHideProfiles, showHideProfiles$] = useObservableCallback(
    identity
  )

  const isShowProfiles = useObservableState(
    useObservable(() =&gt;
      merge(mouseOverOut$, mouseOverOutDelay$, focusBlur$, showHideProfiles$)
    ).pipe(debounceTime(100)),
    false
  )</element></element>
github crimx / ext-saladict / src / selection / select-text.ts View on Github external
export function useInPanelSelect(
  touchMode: AppConfig['touchMode'],
  language: AppConfig['language'],
  doubleClickDelay: AppConfig['doubleClickDelay'],
  newSelection: (payload: Message&lt;'SELECTION'&gt;['payload']) =&gt; void
) {
  const [onMouseUp, mouseUp$] = useObservableCallback(
    event$ =&gt; event$.pipe(filter(e =&gt; e.button === 0))
  )

  const config$ = useObservable(identity, [touchMode, language] as const)

  const clickPeriodCount$ = useObservable(
    inputs$ =&gt;
      inputs$.pipe(
        switchMap(([doubleClickDelay]) =&gt;
          clickPeriodCountStream(mouseUp$, doubleClickDelay)
        )
      ),
    [doubleClickDelay] as const
  )

  const output$ = useObservable(() =&gt;
github crimx / ext-saladict / src / content / components / SaladBowl / SaladBowl.tsx View on Github external
export const SaladBowl: FC = props =&gt; {
  const [onMouseOverOut, mouseOverOut$] = useObservableCallback&lt;
    boolean,
    React.MouseEvent
  &gt;(hoverWithDelay)

  useSubscription(mouseOverOut$, active =&gt; {
    props.onHover(active)
    if (active) {
      props.onActive()
    }
  })

  return (
github crimx / observable-hooks / examples / typeahead / src / custom-input.tsx View on Github external
export const CustomInput: React.FC = props =&gt; {
  const [onChange, textChange$] = useObservableCallback&lt;
    string,
    React.FormEvent
  &gt;(pluckCurrentTargetValue)

  useSubscription(textChange$, props.onChange)

  return (
    <input value="{props.text}" placeholder="Text input" type="text">
  )
}

observable-hooks

React hooks for RxJS Observables. Simple, flexible, testable and performant.

MIT
Latest version published 3 months ago

Package Health Score

72 / 100
Full package analysis