-
Notifications
You must be signed in to change notification settings - Fork 4
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
Refactor MessageTranslator component #105
Comments
Could you give an example of what you mean when you say widget configuration and the conditional rendering? Right now, one consideration is that the *-container widgets that are being sent to the backend are potentially nested, e.g.: The nft-asset-traits-container contains: So we render a full component composed of smaller components, but the composition is being configured at run-time by the backend. |
Yes, this a purely code architecture thing and shouldn't affect any existing functionality. Instead of handling rendering of the components with a switch statement we will pass in an array of configs that have a function name and container/widget logic. And the component will search that array for the correct component to render. It should act the same way as the switch. Below is an example of what I was thinking. For nested components we would need to make sure the configuration is passed into the lower level widgetize function. Definitely open to suggestions on how to improve this, but mainly wanted to highlight the need to refactor the switch logic
|
Ok thanks for clarifying. I am not sure if it is going to be feasible without trying it out, but I think given Widgetize is currently called recursively, it is going to be tricky.
Consider the code above, given we know we're rendering a collection asset container, we know the structure of the args, that it contains a collection and a list of assets. Therefore, we can call Widgetize recursively on the collection and the assets, and pass them into the constructor and children prop of the Thinking about it more, we probably could extract out the switch logic into a function that takes |
The switch statement within this component is getting a little crazy and tough to read. A more readable way to organize this component may be to accept a list of widget configurations and conditionally render a configuration based on the passed in widget function name. An example of what I am thinking of is below.
Note this is for a table component https://react.dev/reference/react/Children#accepting-an-array-of-objects-as-a-prop.
The text was updated successfully, but these errors were encountered: