Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exporting isObservableWritable #11

Closed
wants to merge 2 commits into from

Conversation

wongchichong
Copy link

Exporting isObservableWritable for the following use case

export const Event = ({ camera: cam, scene: sce, renderer: ren, ...props }: { camera?: Observable<Camera>, scene?: Observable<Scene>, renderer?: Observable<Renderer> }) => {
    const meshObj = $<Object3D<Object3DEventMap> & Partial<EventHandlers>>()

    const camera: Observable<Camera> = $$(cam) ? useMemo(() => $$(cam)) : $<Camera>()

    useEffect(() => {
        if (isObservableWritable(camera)) {
            camera(useCameras()[0])
        }
   }

@fabiospampinato
Copy link
Member

fabiospampinato commented Oct 1, 2024

I haven't exposed that API kinda precisely for this reason. IMO read-write segregation is kinda useless (if you are writing typescript) inside the component, but it is very much useful for many reasons when passing reading and writing capability somewhere else.

For example here if the caller had a writable observable to pass to you, but wanted to intercept the write, it would be very awkward to write, because you are accepting a single prop, not a camera and a setCamera prop.

Also let's say the caller has a writable observable but wants to pass only a read-only one to you, they would have to make a read-only observable because if they passed you the writable one it would not be what they wanted to, and that would be an easy mistake to make from their point of view, while if you accepted 2 props it would be cleaner and easier to write this correctly.

Basically as I don't really see a use case for exposing this function to userland, and this function can be implemented in userland if you don't like my reasoning for not exposing it, I don't think exposing this by default is a good idea.

Thanks for the PR though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants