-1

Currently in our web app, we have forms which define model and view in JSON (in-house library) on the client side. Example: enter image description here

And there is a component for each form, which has

  • event handling logics like, clear value of Bar if Foo's value is XYZ. There logics can be complex too.
  • complex validation logics (simple validations are part of JSON itself)

Now, we want to make UI free of all this event handling and complex validation logic to free UI from domain specific code.

Does it make sense to move validation and event handling logic in JSON (using json-logic-js maybe) and get everything including model/view from the backend API?

Will it be a good design?

1
  • Is that logic only for the UI? Not for backend? If so, then you want to introduce a new language (because that's what this JSON thingy is) and push the responsibility for managing it onto backend, with no benefit for the backend. Sorry, that's very bad. Unless backend can use it as well, in which case it is only very complicated with unknown security risks. I suppose this is acceptable if some well known common language is used instead, on both sides. Like JS itself.
    – freakish
    Commented Sep 4 at 21:54

1 Answer 1

0

According to wikipedia JSON...

...is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and arrays (or other serializable values).

...it is structured text without features needed to accommodate behaviour the way complex logic should be.

Now, we want to make UI free of all this event handling...

Event handling it is about invoking behaviour on changes (in case of UI on user requested changes), freeing up the UI from event handling implies replacing the behaviour activation by events with something else. If the user's actions is the behaviour's activation leverage that would be developing a parallel to events behaviour activation leverage that should do what events do. To free up the UI from logic define what logic is and what behaviour activation leverage is and then move logic implementation around anywhere except in the behaviour activation leverage code.

Does it make sense to move validation and event handling logic in JSON (using json-logic-js maybe)...

It isn't possible, hence no.

...and get everything including model/view from the backend API?

It is that way if the application is a client server application where clients request and send information to the server. If it is about a mobile app installed on user(s)'(s) devices probably the logic it is already implemented on the server side and on the client side it is implemented to reduce client server communication, it just needs to be removed from the client side. I guess this question cannot get an accurate answer without including details about the purpose of the logic being implemented on the client side.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.