-
Notifications
You must be signed in to change notification settings - Fork 7
Configurable fields #132
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
Configurable fields #132
Conversation
0c7240f to
77f5070
Compare
There's already an effect to handle this
I disagree with this and see it as premature optimization which complicates things. It should be a single JSON file that can be looped over. The content types are inferred from the keys. In a format where we have multiple files we need an index that points to other files, but what we need is the flexibility to add new fields and types. I am not opposed to moving forward with the PR as is but I really believe we need to have the flexibility to add more content types by just adding new JSON entries, without adding new TypeScript code. |
|
Just to clarify a little (and also backtracking a bit): I am not opposed to having multiple files but adding new content types should be so generic that no code needs to be changed. I tried adding a product as a test and it needs changes in many places in code. |
I don't agree that it is premature optimization, but even if it would be, if there would have been more premature optimization in WordPress, it wouldn't be in the state that it is today. It's my responsibility as an engineer who is concerned with the maintenance burden of software I produce, to predict hot spots of maintenance burden and "prematurely" prevent them. I consider a file that will grow to infinity to be such a hot spot. There's a difference between premature optimization and solid engineering practices. In addition, since I predicted this would be a contentious point, I took steps to minimize the impact of splitting the schema into multiple files, by providing both JavaScript and PHP functions that abstract the fact that those schemas are stored in separate files. The schemas should always be consumed through those functions, and such functions would need to exist anyway even if schemas would be stored in a single file. The fact that schemas are stored in separate files is transparent to code that needs to consume them.
Yes, this is the goal. However, as I mention in the PR description, for this to be possible, I believe the backend must also provide a generic API. Currently, the boundary of where genericity is broken is in |
|
I will be splitting this PR in two, since it's currently doing two things and I would like those things to be addressed in separate PRs:
|
This PR implements the solution described in #101, so that the fields that are available for a given subject (blog post, page, etc), are provided through JSON configuration. Each subject type has its own configuration, which I've named a schema.
Note that I opted for splitting the schema of each subject into it's own file. I think that having all of them in the same file would not scale too well, the file would grow to infinity and become difficult to maintain. So, instead, each subject has its own schema:
Additionally, JavaScript and PHP functions are provided to load the schema of a given subject type:
Frontend
The frontend code has been fully adapted to use the schemas, which means that the code is now generic. All the specific types (
BlogPost,Page,BlogPostBlueprint, etc) have been removed, and the only types left are generic (Subject,Blueprint. This is how the code should have been from day one, we're now reaching the "correct" solution.This results in the code being massively simplified, and adding a new subject type does no longer require changing a bunch of files, and copy-pasting code around.
A new
SubjectsApihas also been introduced, and the specificBlogPostsApiandPagesApiwere removed. However, internally,SubjectsApi, still differentiates between subject types because it needs to call different endpoints depending on the subject type. Once we tackle the backend side of this (see below), I expected that to no longer be necessary.Backend
This PR does not make any changes to the backend. Instead, as mentioned above, it introduces a generic
SubjectsApithat abstracts the fact that the backend hasn't been changed. Once we tackle the backend side of this, I think it would make sense that the backend exposes a generic/subjectsAPI (as opposed to specific/blog-postsor/pages). At that point, theSubjectsApican become truly generic.I took the liberty of opening #133 to track that work.
Screen capture
Screen.Recording.2024-12-02.at.18.16.53.mov