Thursday 4 May 2017

Angular 2 and Node: Client and Server business logic convergence

We always need to perform validation and some business logic both in the server and client side. As we are using Angular2 and node with typescript (TS), we have conclude that a vast amount of the code and class model will be equal except by the persistence model (socket from client to server, sql from node to database).

As the objects can persist itself, we should be able to override just the save() method and so use codes like bellow

<input [ngModel]=‘person.getSomeProperty()’ (ngModelChange)=“person.setSomeProperty($event)“>
...
person.save()

person.save() would send the information to node that would rehydrate the class and perform the same person.save(), but by this time performing the dml into the database.

From this perspective, I have some question regarding the strategy: * Is it sound reasonable to reuse code in such way? The uses cases do match. * Is it correct to create a node module with all the business logic (like 20 classes) and export it to be used by the components? * Can I two way bind to the same person.someMethod() from different components and views?



via Encoder

No comments:

Post a Comment