We need generic service for generating JSON Patch requests based on model changes.
An app provides API for listing and updating various objects. Each object type has it's own endpoint. We want to issue XHR requests to update backend on every model change. In order to avoid sending back and forth full objects we will only send JSON Patches.
Your goal is to implement the service that would watch for changes on given object and issue JSON Patch requests to the backend. Make the service as reusable as possible. For generating patches you can use https://www.npmjs.com/package/fast-json-patch. The service should be configurable like this:
Which means that
object will be watched as long as
$scope is not destroyed. If there are any changes then JSON Patch should be created and sent
to the backend to
PATCH HTTP method where
:id is value of
object.id. User may also provide id explicitly.
Sometimes there is a need to ignore some properties, as they are being used only on the frontend and should not be saved to the backend.
By default ignore
$$hashKey property and if user wants to ignore others, let them specify that explicitely.
callback is provided then instead of sending request to the backend the
callback should be invoked with JSON Patch data.
For now there are two entities: attraction and note. Here is the API you might need to interact with in order to finish this task.
Please note that the API is mocked on the frontend, so if you reload browser window all posted data will be lost.
To install dependencies from package.json:
To install dependencies from bower.json:
To run tests in development mode:
To run verify jshint, tests and coverage:
To run verify jshint, tests and coverage with human readable output:
To start browser in live reload mode: