Advertisement
codemonkeynorth

app hook

Apr 2nd, 2025
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TypeScript 1.40 KB | Source Code | 0 0
  1.  
  2.  
  3. import AppCommand from "../../commands/AppCommand"
  4.  
  5. import { useCallback, useMemo } from "react"
  6. import { useBus } from "react-bus"
  7.  
  8. const useCoreAppFunctions = () => {
  9.   //
  10.   const bus = useBus()
  11.  
  12.   const nextImage = useCallback(() => {
  13.     //alert("useAppFunctions::nextImage")
  14.     bus.emit(AppCommand.NEXT_IMAGE)
  15.   }, [bus])
  16.  
  17.   const previousImage = useCallback(() => {
  18.     //alert("useAppFunctions::previousImage")
  19.     bus.emit(AppCommand.PREV_IMAGE)
  20.   }, [bus])
  21.  
  22.   const functions = useMemo(() => {
  23.     return {
  24.       core: {
  25.         nextImage,
  26.         previousImage,
  27.       },
  28.     }
  29.   }, [nextImage, previousImage])
  30.  
  31.   const receiver = functions
  32.  
  33.   const app = {
  34.     functions,
  35.     receiver,
  36.   }
  37.  
  38.   return app
  39. }
  40.  
  41. export default useAppFunctions
  42.  
  43.  
  44.  
  45. import {
  46.   CoreAppFunctions,
  47.   CoreAppReceiver,
  48.   default as useCoreAppFunctions,
  49. } from "@core/features/app/hooks/functions/useCoreAppFunctions"
  50.  
  51.  
  52. // TODO: we'll need to use some memoization if we useBus
  53.  
  54. const useAppFunctions = () => {
  55.   //
  56.   const core = useCoreAppFunctions().functions.core
  57.  
  58.   const foo = (window_id: number) => {
  59.     console.log(`foo: ${window_id}`)
  60.   }
  61.  
  62.  
  63.   const test = {
  64.     foo,
  65.   }
  66.  
  67.   const functions: AppFunctions = {
  68.     core,
  69.     test,
  70.   }
  71.  
  72.   const receiver = functions
  73.  
  74.   const app = {
  75.     functions,
  76.     receiver,
  77.   }
  78.  
  79.   return app
  80. }
  81.  
  82. export default useAppFunctions
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement