ClientSynchronizer
An instance of this class will be able to handle tasks needed to implement
Differential Synchronization for a specific type of documents.
<T> the type of Documents that this synchronizer can handle
<D> the type of Edits that this synchronizer can handle
<P> the type of PatchMessage that this synchronizer can handle
-
Called when the shadow should be patched. Is called when an update is recieved.
Declaration
Swift
func patchShadow(edit: D, shadow: ShadowDocument<T>) -> ShadowDocument<T>Parameters
editthe Edit containing the diffs/patches.
shadowDocumentthe ShadowDocument to be patched.
Return Value
ShadowDocument a new patched shadow document.
-
Called when the document should be patched.
Declaration
Swift
func patchDocument(edit: D, clientDocument: ClientDocument<T>) -> ClientDocument<T>Parameters
editthe Edit containing the diffs/patches.
documentthe ClientDocument to be patched.
Return Value
ClientDocument a new patched document.
-
Produces a Edit containing the changes between updated ShadowDocument and the ClientDocument. This method would be called when the client receives an update from the server and need to produce an Edit to be able to patch the ClientDocument.
Declaration
Swift
func clientDiff(clientDocument: ClientDocument<T>, shadow: ShadowDocument<T>) -> DParameters
shadowDocumentthe ShadowDocument patched with updates from the server
documentthe ClientDocument.
Return Value
Edit the edit representing the diff between the shadow document and the client document.
-
Produces a Edit containing the changes between the updated ClientDocument and the ShadowDocument.
Calling the method is the first step in when starting a client side synchronization. We need to gather the changes between the updates made by the client and the shadow document. The produced Edit can then be passed to the server side.Declaration
Swift
func serverDiff(serverDocument: ClientDocument<T>, shadow: ShadowDocument<T>) -> DParameters
documentthe ClientDocument containing updates made by the client.
shadowDocumentthe ShadowDocument for the ClientDocument.
Return Value
Edit the edit representing the diff between the client document and it’s shadow document.
-
Creates a PatchMessage by parsing the passed-in json.
Declaration
Swift
func patchMessageFromJson(json: String) -> P?Parameters
jsonthe json representation of a PatchMessage.
Return Value
PatchMessage the created PatchMessage.
-
Creates a new PatchMessage with the with the type of Edit that this synchronizer can handle.
Declaration
Swift
func createPatchMessage(id: String, clientId: String, edits: [D]) -> P?Parameters
documentIdthe document identifier for the PatchMessage.
clientIdthe client identifier for the PatchMessage.
editsthe Edits for the PatchMessage.
Return Value
PatchMessage the created PatchMessage.
-
Adds the content of the passed in content to the ObjectNode.
When a client initially adds a document to the engine it will also be sent across the wire to the server. Before sending, the content of the document has to be added to the JSON message payload. Different implementation will require different content types that the engine can handle and this give them control over how the content is added to the JSON string representation.
For example, a ClientEngine that stores simple text will just add the contents as a String, but one that stores JsonNode object will want to add its content as an object.Declaration
Swift
func addContent(content:ClientDocument<T>, fieldName:String, inout objectNode:String)Parameters
contentthe content to be added.
objectNodeas a string to add the content to.
fieldNamethe name of the field.
View on GitHub
ClientSynchronizer Protocol Reference