tweakpane / use-tweaks

🎛️ Tweak React components with Tweakpane
https://codesandbox.io/s/use-tweaks-example-58e02
MIT License
768 stars 23 forks source link

Monitors #12

Closed gsimone closed 3 years ago

gsimone commented 4 years ago

API for monitors, maybe a fn that hides constants or something

const  { mouseMonitor, x, y  } = useTweaks({ mouseMonitor: makeMonitor('2d'), x: 1, y: 1 })

// alt
const  { mouseMonitor, x, y  } = useTweaks({ mouseMonitor: { type: "MONITOR" }, x: 1, y: 1 })

useFrame(() => {
   mouseMonitor.set(mouse.x)

   // alt
  mouseMonitor(mouse.x)
})
CptCompiler commented 3 years ago

hey @gsimone, why did you close this issue? Is there any way to use monitors? Thanks. Nice work so far!

dbismut commented 3 years ago

Reopening! Pretty sure Gianmarco was already thinking of the new magic api he has in mind, but first things first!

gsimone commented 3 years ago

Hey @CptCompiler we had them working in the previous API, but weren't too happy about it. Monitors are special in that they have to be imperatively set by the user, original API was something like:

const [monitor,setMonitor] = createMonitor(...)

useTweaks(monitor)

// your imperative code
setMonitor(4)

Opinions?

gsimone commented 3 years ago

@dbismut proposes using a ref, which we feel is more react-like

const ref = useRef(0)
useTweaks("Monitor", {
  ...otherTweaks,
  ...makeMonitor(ref, "MyMonitorName", ...settings))
}

// setting the ref value to update the monitor
useFrame(({ clock }) => { ref.current = Math.sin(clock.getElapsedTime()) })
CptCompiler commented 3 years ago

Thanks for your fast replies, guys!

Hmm... I think I would prefer refs as well. Sounds good.

gsimone commented 3 years ago

If you want you can give some feedback in PR #35

CptCompiler commented 3 years ago

Yeah... thank you very much. Keep up the good work! 🎉