gcanti / tcomb

Type checking and DDD for JavaScript
MIT License
1.89k stars 120 forks source link

tcomb objects for application data models? #316

Closed maps82 closed 4 years ago

maps82 commented 6 years ago

Hi!

This is not a bug, but a more general question.

I'm currently writing a react app to create/view/edit json data from a rest api (simplified).

I thought it would be nice to not only pass individual json fields from the api to the components but actually have a nice data model with classes that represent the business domain (i.e. a User with all it's properties). When I stumbled over tcomb I though that's it! API validation and immutable js objects - perfectly - at least for a read only view.

But I have problems with the "create" case: Normally you would start creating an empty Object (new User()) and then call setters or just assign values to it's properties before posting everything to the API (not possible because of the need of the constructor). In the simple User example it's easy, you can construct the object when you have all data - although it's maybe unsuitable to have such an object in redux directly then. But for more complex objects it's not.

So is tcomb suitable for implementing the data model of an application or is it "just" for deserialization? If not how do others use it? How can I use it to construct an empty object and fill it step by step with data, w/o having separate non-tcomb object?