JSON-Based Component Rendering Proof-of-concept #110
alexstandiford
started this conversation in
Show and tell
Replies: 1 comment
-
Looks pretty cool, I think you’re right that the idea that you could edit the JSON/config without having to do a rebuild is intentionally lowering the bar towards maintenance of a project like that. That validationRules part is very interesting! Most of what we’ve done with Fields API has not had any conditional logic built in and is a pretty cool example of how that might look. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I conceptualized a JSON-based methodology that can render a button, provide it instructions, and also store the data related to the button to use for React-based state changes. While I am not necessarily convinced this is a 1:1 with the fields API, I do think it's along a similar vein, and wanted to share, since I think some of the concepts I've come up with here may apply in what we end up doing.
The key goal of this particular API is to make it possible for a front end interface to be rendered entirely by any backend, provided the front-end knows how to parse the JSON and render the output from it. This decouples the frontend from the actual rendering, which makes it possible to dynamically change the interface from the backend without writing any specific platform code. I think this is a key component of the future of WordPress, since doing it this way would enable any future admin UI to work natively in an iOS application as well as a web application. You would still have two apps, but everything that actually renders the output is based on the JSON, and therefore can be extended easily.
The JSON is broken into 4 parts:
There's no shortage of ways this could be handled. I personally built this out using a basic object-based datastore, but we would likely use redux in WordPress to handle the stores, particularly since we're already using that system now anyway.
There's really not much to the actual button component. It basically works with a react hook
useDynamicPropAdapter
, which just converts the JSON input into the actual props the button should use.Here's the adapter. It could definitely be done in a neater fashion, and probably should have multiple adapters built into it instead of a single ever-growing monolithic one, but I just wanted to throw something together quickly.
Beta Was this translation helpful? Give feedback.
All reactions