TrackChangesAdapter
Track changes adapter.
The track changes adapter is an object that communicates asynchronously with the data source to fetch or save the suggestion data. It is used internally by the track changes feature whenever a suggestion is loaded, created or deleted.
The adapter is optional. You might need to provide it if you are features/collaboration/track-changes/track-changes-integration using the track changes feature without real-time collaboration.
To set the adapter, overwrite the TrackChanges#adapter property.
Methods
addSuggestion( suggestionData ) → Promise<SuggestionData>module:track-changes/trackchanges~TrackChangesAdapter#addSuggestionCalled each time a new suggestion is created.
The method should save the suggestion data in the database and return a promise that should be resolved when the save is completed.
If the promise resolves with an object with the
createdAtproperty, this suggestion property will be updated in the suggestion in the editor. This lets you update the suggestion data with server-side information.The
suggestionDataobject does not expect theauthorIdproperty. For security reasons, the author of the suggestion should be set on the server side.If
suggestionData.originalSuggestionIdis set, the new suggestion should have theauthorIdproperty set to the same as the suggestion withoriginalSuggestionId. This happens when one user splits another user's suggestion, creating a new suggestion as a result. See Track changes integration guide.Note: Failure to properly handle this property will result in editor crash in some scenarios.
In any other case, use the current (local) user to set
authorId.The
suggestionDataobject does not expect thecreatedAtproperty either. You should use the server-side time generator to ensure that all users see the same date.It is recommended to stringify
suggestionData.attributesvalue to JSON and save it as a string in your database, and then to parse the strings when loading suggestions.Parameters
suggestionData : AddSuggestionInput
Returns
Promise<SuggestionData>
getSuggestion( id ) → Promise<SuggestionData>module:track-changes/trackchanges~TrackChangesAdapter#getSuggestionCalled each time the suggestion data is needed.
The method should return a promise that resolves with the suggestion data object.
Parameters
id : stringThe ID of the suggestion to get.
Returns
Promise<SuggestionData>
updateSuggestion( id, suggestionData ) → Promise<void>module:track-changes/trackchanges~TrackChangesAdapter#updateSuggestionCalled each time the suggestion properties change.
The method should update the suggestion properties in the database and return a promise that should be resolved when the save is completed.
Keep in mind that the
dataparameter only contains those properties of a suggestion which changed.Parameters
id : stringsuggestionData : UpdateSuggestionInput
Returns
Promise<void>