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

Check if component is defined in react_component() #474

Open
kamilzyla opened this issue Jul 6, 2023 · 0 comments
Open

Check if component is defined in react_component() #474

kamilzyla opened this issue Jul 6, 2023 · 0 comments

Comments

@kamilzyla
Copy link
Collaborator

Background & problem

With #473 it is now possible to define React components in app/js and seamlessly use them in R code. The component definition must be registered with the JS function Rhino.registerReactComponents() and then declared in R using rhino::react_component(). The name passed to these functions must match exactly. Unfortunately rhino::react_component() won't raise an error if no component with the given name is registered. Only after running the application one will be able to see in the JS console that there are React errors.

Goal

Ideally rhino::react_component() would raise an error if no component with the given name is registered.

Approach

Such a check would require two pieces of information:

  1. What components are available (defined and registered with Rhino.registerReactComponents()).
  2. What components are needed (declared with react_component() and used).

Here are some theoretical ideas to get the list of available components:

  1. Parse the sources in app/js looking for calls to Rhino.registerReactComponents().
  2. Execute the built app.min.js and retrieve the jsmodule.RhinoReact object.
  3. Register the components with some kind of a config file, which would be easier to parse then JS code.
  4. Register the components with some kind of a mechanism, which would allow to generate a list of available components in easily-digestible form during build_js().

And here are some theoretical ideas at which point we could determine what components are needed:

  1. As an additional check for lint_r().
  2. When the react_component() function is called.
  3. When the component function is called (the return value of react_component()).
  4. When the application is launched.

Possibly some combination of (4) (available) and (2) (needed) could have a chance to work, but it does seem like a serious endeavor.

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

No branches or pull requests

1 participant