Causality
public struct Causality
Causality is a very simple event bus for Swift. Events may have associated data and are fully typed. Causality also allows for monitoring State changes.
-
The queue used by the default bus for thread-safety. Also the default queue used for all buses (unless specified on initialization).
Declaration
Swift
static let globalQueue: DispatchQueue
-
A default/global bus
Declaration
Swift
static let bus: Causality.Bus
-
Subscriptions can have the following statuses:
See moreDeclaration
Swift
enum SubscriptionStatus
-
Subscription identifier used by subscribers to be able to unsubscribe. Callers should make no assumptions about the underlying type of a
Subscription
. (i.e. it may change to a struct, class, or protocol at some point)Declaration
Swift
typealias SubscriptionId = UUID
-
A Bus for events to go from publishers to subscribers
See moreDeclaration
Swift
class Bus
-
Underlying type for EventIds (do not rely on this always being a UUID)
Declaration
Swift
typealias EventId = UUID
-
A type-erased form of an Event. Callers usally do not need to worry about this.
See moreDeclaration
Swift
class AnyEvent<Message> : CausalityAddress
-
Declare events to be used as endpoints for publish or subscribe calls.
Example:
static let SomeEvent = Causality.Event<Int>(label: "Some Event")
This declares
See moreSomeEvent
as an event that will require anInt
on publish and will pass the sameInt
to the subscription handler. -
DynamicEvent
can be used if you need to uniquely identify states by paramter. To properly declare yourDynamicEvent
, ensure you define yourCodingKeys
and overrideencode()
to conform to Encodable. All keys that you want to be included in the unique identification should be specified inencode()
. -
Custom types used as messages should conform to
Message
Declaration
Swift
typealias Message = Any
-
A convenience message that can be included for events that have no associated data
Declaration
Swift
struct NoMessage : Message
-
Type-erased StateValue
Declaration
Swift
typealias AnyStateValue = Any
-
Custom type for
State
infoDeclaration
Swift
typealias StateValue = AnyStateValue & Equatable
-
Base class that
See moreState<Causality.StateValue>
andDynamicState<Causality.StateValue>
conform to.Declaration
Swift
class AnyState<Value> : CausalityAnyState where Value : Equatable
-
Declare states with typed values as labels to be used for
set()
andsubscribe()
calls.Example:
static let SomeState = Causality.State<Int>(label: "Some State")
This declares
See moreSomeState
as an state that will pass anInt
to subscribers whenever the value changes. -
DynamicState
can be used if you need to uniquely identify states by paramter. To properly declare yourDynamicState
, ensure you define yourCodingKeys
and overrideencode()
to conform to Encodable. All keys that you want to be included in the unique identification should be specified inencode()
.