CombineWrapper
public final class CombineWrapper : WebcomWrapper, CustomDebugStringConvertible
The type that wraps DatasyncManager
in order to enrich it with a Combine-based API.
See also the documentation section of WebcomWrapper
for the corresponding wrapped type.
To use this type, import the following dependency in your code:
import WebcomCombine
-
Declaration
Swift
public let wrapped: DatasyncManager
-
Returns a reference to a database node.
This method only returns
nil
when thepath
is ill-formed, that is when it contains forbidden characters. All nodes always exists: this method always returns a plain node reference when thepath
is syntactically valid. From a theoretical point of view, the concept on existence is a nonsense. From a practical point of view, we can consider that a node exists when its value is notnull
(the JSONnull
value, not to be confused with the Swiftnil
keyword).Creating a node reference is an extremely light-weight operation, so as many as desired can be created without worrying about wasting bandwidth or memory. It is possible to create several references for the same path. Each piece of code should declare the references it needs, without trying to factorize or cache anything.
The path consists of segments separated by
/
(slash) characters. Each segment corresponds to a move in the database tree:- The starting point is the root node of the database tree
- The
.
segment is a no-operation. - The
..
segment indicates to go one level up in the tree. When already at the root node, this is a no-operation. - The empty segment, when using a
/
at the beginning or at the end of thepath
, or when using several consecutive/
, is a no-operation. - Any other valid segment indicates to go one level down towards the so-named child.
Examples:
- If
path
is equal tofoo
,/foo
,foo/
or/foo/
, the path of the resulting node is/foo
. - If
path
is equal tofoo/bar
,/foo/./bar
orfoo/geek/../bar/
, the path of the resulting node is/foo/bar
. - If
path
is equal tofoo/bar/../geek/noob
or/foo/bar/../geek/noob/.
orfoo//bar/../geek/./noob/.
, the path of the resulting node is/foo/geek/noob
. If
path
is equal tofoo/..//..
, the resulting node is the root node.
Declaration
Swift
public func node(for path: String) -> DatasyncNode.CombineWrapper?
Parameters
path
The absolute path of the node to refer. It can start or not with a
/
(slash) character. It is always absolute.Return Value
A reference to the node corresponding to the
path
when thepath
is valid,nil
otherwise. -
Returns a reference to the database root node.
Declaration
Swift
public var rootNode: DatasyncNode.CombineWrapper? { get }
-
Returns a reference to a database node.
This operator returns:
manager.node(for: path)
Declaration
Swift
public static func / (manager: CombineWrapper, path: String) -> DatasyncNode.CombineWrapper?
Parameters
manager
The manager to use to get the node reference.
path
The path of the node to refer.
Return Value
A reference to the node corresponding to the
path
when thepath
is valid,nil
otherwise. -
Creates a publisher that produces a
DatasyncState
value each time the state of the web socket changes.Subscriptions made with the returned publisher must be stored explicitly to remain active, e.g. using the
AnyCancellable.store(in:)
method. Unlike callback-based subscriptions made with theDatasyncManager.subscribeToStateChange(stores:file:line:queue:onChange:onCompletion:)
method, these subscriptions are not stored implicitly.Declaration
Swift
public func statePublisher(file: StaticString = #fileID, line: UInt = #line) -> AnyPublisher<DatasyncState, Never>
Return Value
A type-erased publisher that produces
DatasyncState
values and never fails. -
Creates a publisher that produces a value each time user currently authenticated on the web socket changes.
Subscriptions made with the returned publisher must be stored explicitly to remain active, e.g. using the
AnyCancellable.store(in:)
method. Unlike callback-based subscriptions made with theDatasyncManager.subscribeToCurrentUIDChange(stores:file:line:queue:onChange:onCompletion:)
method, these subscriptions are not stored implicitly.Declaration
Swift
public func currentUIDPublisher(file: StaticString = #fileID, line: UInt = #line) -> AnyPublisher<String?, Never>
Return Value
A type-erased publisher that produces user identifiers and never fails.
-
Removes all
AnyCancellable
instances stored in this manager.These instances were stored using the
AnyCancellable.store(in:)
method.If this manager stored the last reference to an
AnyCancellable
instance, then this one will be cancelled, since theAnyCancellable
deinitializer calls theCancellable.cancel()
method.Usually, there is no need to call this method since it is done automatically when this manager is deinitialized.
Declaration
Swift
public func removeAllAnyCancellable()
-
Gets the value of the node at a given path.
Declaration
Swift
public func decodedValue<T>(at path: String) -> WebcomFuture<T> where T : Decodable
Parameters
path
The path of the node whose value must be returned.
Return Value
A future with the decoded value of the node at the
path
. -
decodedValue(at:
Asynchronous) Declaration
Swift
public func decodedValue<T>(at path: String) async throws -> T where T : Decodable
-
Clears the value of the node at a given path.
Declaration
Swift
@discardableResult public func clear(at path: String) -> WebcomFuture<Void>
Parameters
path
The path of the node whose value must be cleared.
Return Value
A future with a void value.
-
clear(at:
Asynchronous) Declaration
Swift
public func clear(at path: String) async throws
-
Sets the value of the node at a given path.
All children of the referred node cleared before setting the new value.
Declaration
Swift
@discardableResult public func set(_ value: (some Encodable)?, at path: String) -> WebcomFuture<Void>
Parameters
value
The value to set. It will be encoded to JSON before being sent to the back-end, using the
jsonDecoder
of theWebcomApplication
from which this manager derives. Thenull
value can be specified withnil
orNSNull()
.path
The path of the node whose value must be set.
Return Value
A future with a void value.
-
set(_:
Asynchronousat: ) Declaration
Swift
public func set(_ value: (some Encodable)?, at path: String) async throws
-
Merges a value with the current value of the node at a given path.
Unlike what happens with the
set(_:at:)
:value
may not benil
,- the encoding of
value
to JSON must give a JSON object (or a JSON array but this is discouraged), or the method will fail, existing direct children (i.e. the descendants at the first level of depth) that exist in the current value are preserved when
value
does not specify them.
Declaration
Swift
@discardableResult public func merge(with value: some Encodable, at path: String) -> WebcomFuture<Void>
Parameters
value
The value to merge with. It will be encoded to JSON before being sent to the back-end, using the
WebcomApplication.jsonEncoder
of theWebcomApplication
from which this node derives.path
The path of the node whose value must be set.
Return Value
A future with a void value.
-
merge(with:
Asynchronousat: ) Declaration
Swift
public func merge(with value: some Encodable, at path: String) async throws
-
Adds a new child with the given value to the node at a given path.
Declaration
Swift
@discardableResult public func push(_ value: (some Encodable)?, at path: String) -> WebcomFuture<DatasyncNode.CombineWrapper>
Parameters
value
The value to set for the created child. It will be encoded to JSON before being sent to the back-end, using the
jsonDecoder
of theWebcomApplication
from which this manager derives. Thenull
value can be specified withnil
orNSNull()
.path
The path of the node to which a child must be added.
Return Value
A future with the new child.
-
push(_:
Asynchronousat: ) Declaration
Swift
public func push(_ value: (some Encodable)?, at path: String) async throws -> DatasyncNode.CombineWrapper
-
Declaration
Swift
public var debugDescription: String { get }