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.

Types

  • A value representing an operation to be performed by a transaction on a given node.

    See more

    Declaration

    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 more

    Declaration

    Swift

    @frozen
    public enum Status : Equatable
  • A value representing the result of running a transaction on a given node.

    See more

    Declaration

    Swift

    public struct Result

Basic Transactions

  • 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), the defaultValue 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 (respectively false) value, it is set to false (respectively true).

    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), the ping value is set.

    When the node exists and its initial value is not decodable neither to ping nor to pong, the transaction is aborted.

    When the node initial value is decodable to ping (respectively pong), it is set to pong (respectively ping).

    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 and pong.

  • 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), the json 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 the writeIfNone(_:) overload that takes an Encodable 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), the value 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 the WebcomApplication from which the node derives.

    Return Value

    A transaction that sets value to the node when it does not exist.