Design Service Interaction
The details of interaction with the back endâthe GET, POST, and DELETE requestsâwill be put away in a separate service object. The controllerâs getTasks function need not worry about them. It only has to make a call to the service and pass one callback for success and another for the error situation. These callbacks will be responsible for appropriately updating the models in the controllers.
From the design point of view, this approach makes the code modular and keeps the concerns apart in the code. From the testing point of view we donât want the controller to interact with the real service for two reasons. One, we havenât written the service yet. Two, interacting with the real service would make the test ...
Get Test-Driving JavaScript Applications now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.