DatasyncTransaction
public enum DatasyncTransaction
A namespace for stuff related to transactions.
This enumeration does not contain any case
, since it is only used as a namespace.
-
A value representing an operation to be performed by a transaction on a given node.
See moreDeclaration
Swift
public enum Operation
-
A type representing a function to run on a node in a transactional way.
Declaration
Swift
public typealias Function = (_ value: DatasyncValue) -> Operation
Parameters
value
The current value of the node.
Return Value
An operation to be performed on the node value.
-
A value representing the status of a terminated transaction.
See moreDeclaration
Swift
@frozen public enum Status : Equatable
-
A value representing the result of running a transaction on a given node.
See moreDeclaration
Swift
public struct Result
-
Returns a transaction function that toggle the boolean value of the node.
When the node does not exist (in other words, when its initial value is
null
), thedefaultValue
is set.When the node exists and its initial value is not a boolean, the transaction is aborted.
When the node has initially the
true
(respectivelyfalse
) value, it is set tofalse
(respectivelytrue
).Declaration
Swift
public static func toggle(defaultValue: Bool = false) -> Function
Parameters
defaultValue
The final value of the node when it does not exist.
Return Value
A transaction that toggle the value of the node when it is a boolean.
-
Returns a transaction function that toggle the boolean value of the node.
When the node does not exist (in other words, when its initial value is
null
), theping
value is set.When the node exists and its initial value is not decodable neither to
ping
nor topong
, the transaction is aborted.When the node initial value is decodable to
ping
(respectivelypong
), it is set topong
(respectivelyping
).Declaration
Swift
public static func toggle<T>(between ping: T, and pong: T) -> Function where T : Decodable, T : Encodable, T : Equatable
Parameters
ping
The first of the two values to toggle between.
pong
The second of the two values to toggle between.
Return Value
A transaction that toggle the value of the node between
ping
andpong
. -
Returns a transaction that sets the value of the node when it does not exist.
When the node does not exist (in other words, when its initial value is
null
), thejson
value is set. Otherwise the transaction is aborted.Declaration
Swift
public static func writeIfNone(_ raw: WebcomMarkers.Raw, _ json: Any?) -> Function
Parameters
raw
Use the
.raw
value to disambiguate with thewriteIfNone(_:)
overload that takes anEncodable
parameter.json
The value to set when the node does not exist.
Return Value
A transaction that sets
json
to the node when it does not exist. -
Returns a transaction that sets the value of the node when it does not exist.
When the node does not exist (in other words, when its initial value is
null
), thevalue
value is set. Otherwise the transaction is aborted.Declaration
Swift
public static func writeIfNone(_ value: some Encodable) -> Function
Parameters
value
The value to set when the node does not exist. It will be encoded to JSON before being sent to the back-end, using the
WebcomApplication.jsonDecoder
of theWebcomApplication
from which the node derives.Return Value
A transaction that sets
value
to the node when it does not exist.