Thursday 24 October 2019

DRY form field definitions in express

Coming from a monolithic CMS background (Drupal, Wordpress, etc), I've got a question for those of you building on a modern stack. Recently I've been building a decoupled app using a js framework on the front and node(express) rest api on the back. The dev experience overall is GREAT compared to the oldschool PHP world. That said, I have one pretty big pain point that I'm wondering if anyone else has solved:With oldschool CMS' if you want a field on a piece of content, you add a field, give it a name, hit save. Easy. With the new architecture however the process is as follows: first, add the field to your form, then add the field to your front end model, then add the frontend validation for the field, then add the frontend submission handler for the field, then add the backend submission handler, then the backend validation, then add the field to the backend model, and finally write backend migrations for the field - and this isn't even including the use of a store, which you probably will. In all you've created at minimum 8 different files, spread out over two codebases, with a ton of duplication/replication throughout.Is this really what people are doing every time they want to add or update a field? This seems crazy to me. I feel like there should be some way of defining your fields/models ONCE, in a single file, and then have that file be used by the front and backend, for everything from form building to validation and submission. Is there is some sort of industry standard practice for doing this that I'm missing? The process described above seems unnecessarily complex and not at all in line with the DRY approach. Why is basic CRUD this messy?Someone enlighten me please!

Submitted October 24, 2019 at 08:51PM by eljimado

No comments:

Post a Comment