EntityStore
public class EntityStore
Manages entities lifecycle and synchronisation
-
Declaration
Swift
public typealias Update<T> = (inout T) -> Void -
Create a new EntityStore instance optionally with a queue and a logger
Declaration
Swift
public convenience init(queue: DispatchQueue? = nil, logger: Logger? = nil)Parameters
queuethe queue on which to receive updates. If nil identitymap will create its own.
loggera logger to follow/debug identity internal state
-
Store an entity in the storage. Entity will be stored only if stamp (
modifiedAt) is higher than in previous insertion.Declaration
Swift
public func store<T: Identifiable>( entity: T, named: AliasKey<T>? = nil, modifiedAt: Stamp? = nil, ifPresent update: Update<T>? = nil ) -> EntityObserver<T>Parameters
entitythe element to store in the identity map
namedan alias to reference the entity and retrieve it using it
modifiedAtif entity was already stored it will be used to determine if the update should be applied or discarded
ifPresentapplies the closure before storing it if it’s already been stored. In this case this is similar as calling
updateReturn Value
an object to observe changes on the entity
-
Store an aggregate in the storage. Each aggregate entities will be stored only if stamp (
modifiedAt) is higher than in previous insertion. Finally aggregate will be stored accordingly to each of its entities.Declaration
Swift
public func store<T: Aggregate>( entity: T, named: AliasKey<T>? = nil, modifiedAt: Stamp? = nil, ifPresent update: Update<T>? = nil ) -> EntityObserver<T>Parameters
entitythe aggregate to store in the identity map
namedan alias to reference the aggregate and retrieve it using it
modifiedAtif aggregate was already stored it will be used to determine if the update should be applied or discarded
ifPresentapplies the closure before storing it if it’s already been stored. In this case this is similar as calling
updateReturn Value
an object to observe changes on the entity
-
Store multiple entities at once
Declaration
Swift
public func store<C: Collection>(entities: C, named: AliasKey<C>? = nil, modifiedAt: Stamp? = nil) -> EntityObserver<[C.Element]> where C.Element: Identifiable -
store multiple aggregates at once
Declaration
Swift
public func store<C: Collection>(entities: C, named: AliasKey<C>? = nil, modifiedAt: Stamp? = nil) -> EntityObserver<[C.Element]> where C.Element: Aggregate -
Try to find an entity/aggregate in the storage.
Declaration
Swift
public func find<T>(_ type: T.Type, id: T.ID) -> EntityObserver<T>? where T : IdentifiableParameters
typethe entity type
idthe entity id
Return Value
nil if not found, an
EntityObserver` otherwise -
Try to find an entity/aggregate registered under
namedaliasDeclaration
Swift
public func find<T>(named: AliasKey<T>) -> EntityObserver<T?> where T : IdentifiableParameters
namedthe alias to look for
-
Try to find a collected registered under
namedaliasDeclaration
Swift
public func find<C>(named: AliasKey<C>) -> EntityObserver<C?> where C : CollectionReturn Value
an observer returning the alias value. Note that the value will be an Array
-
Updates an already stored entity using a closure. Useful to update a few properties or when you assume the entity should already be stored. Note: the closure is evaluated before checking
modifiedAt. As such the closure execution does not mean the change was appliedDeclaration
Return Value
true if entity exists and might be updated, false otherwise. The update might not be applied if modifiedAt is too old
-
Updates an already stored alias using a closure. This is useful if you don’t have a full entity for update but just a few attributes/modifications. Note: the closure is evaluated before checking
modifiedAt. As such the closure execution does not mean the change was appliedDeclaration
Return Value
true if entity exists and might be updated, false otherwise. The update might not be applied if modifiedAt is too old
-
Updates an already stored alias using a closure. Note: the closure is evaluated before checking
modifiedAt. As such the closure execution does not mean the change was appliedDeclaration
Return Value
true if entity exists and might be updated, false otherwise. The update might not be applied if modifiedAt is too old
-
Updates an already stored alias using a closure. Note: the closure is evaluated before checking
modifiedAt. As such the closure execution does not mean the change was appliedDeclaration
Return Value
true if entity exists and might be updated, false otherwise. The update might not be applied if modifiedAt is too old
-
Updates an already existing collection alias content Note: the closure is evaluated before checking
modifiedAt. As such the closure execution does not mean the change was appliedDeclaration
Return Value
true if entity exists and might be updated, false otherwise. The update might not be applied if modifiedAt is too old
-
Updates an already existing collection alias content Note: the closure is evaluated before checking
modifiedAt. As such the closure execution does not mean the change was appliedDeclaration
Return Value
true if entity exists and might be updated, false otherwise. The update might not be applied if modifiedAt is too old
-
Removes an alias from the storage
Declaration
Swift
public func removeAlias<T>(named: AliasKey<T>) -
Removes an alias from the storage
Declaration
Swift
public func removeAlias<C>(named: AliasKey<C>) where C : Collection -
Removes all alias from identity map
Declaration
Swift
public func removeAllAlias() -
Removes all alias AND all objects stored weakly. You should not need this method and rather use
removeAlias. But this can be useful if you fear retain cyclesDeclaration
Swift
public func removeAll()