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
  • bus

    A default/global bus

    Declaration

    Swift

    static let bus: Causality.Bus
  • Subscriptions can have the following statuses:

    See more

    Declaration

    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
  • Bus

    A Bus for events to go from publishers to subscribers

    See more

    Declaration

    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 more

    Declaration

    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 SomeEvent as an event that will require an Int on publish and will pass the same Int to the subscription handler.

    See more

    Declaration

    Swift

    class Event<Message> : Causality.AnyEvent<Message> & Hashable
  • Undocumented

    Declaration

    Swift

    typealias CustomEvent<Message> = Causality.AnyEvent<Message> & Hashable
  • DynamicEvent can be used if you need to uniquely identify states by paramter. To properly declare your DynamicEvent, ensure you define your CodingKeys and override encode() to conform to Encodable. All keys that you want to be included in the unique identification should be specified in encode().

    Declaration

    Swift

    class DynamicEvent<Message> : Causality.AnyEvent<Message> & Encodable
  • Subscription handler for Events. Used to unsubscribe() or determine the bus or state that triggered an update.

    See more

    Declaration

    Swift

    public class EventSubscription<Event, Message> : CausalityAnyEventSubscription where Event : Causality.AnyEvent<Message>
  • Subscription handler for States. Used to unsubscribe() or determine the bus or state that triggered an update.

    See more

    Declaration

    Swift

    class StateSubscription<State, Value> : CausalityAnyStateSubscription where State : Causality.AnyState<Value>, Value : Equatable
  • 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 info

    Declaration

    Swift

    typealias StateValue = AnyStateValue & Equatable
  • Base class that State<Causality.StateValue> and DynamicState<Causality.StateValue> conform to.

    See more

    Declaration

    Swift

    class AnyState<Value> : CausalityAnyState where Value : Equatable
  • Declare states with typed values as labels to be used for set() and subscribe() calls.

    Example:

    static let SomeState = Causality.State<Int>(label: "Some State")
    

    This declares SomeState as an state that will pass an Int to subscribers whenever the value changes.

    See more

    Declaration

    Swift

    class State<Value> : Causality.AnyState<Value> & Hashable where Value : Equatable
  • DynamicState can be used if you need to uniquely identify states by paramter. To properly declare your DynamicState, ensure you define your CodingKeys and override encode() to conform to Encodable. All keys that you want to be included in the unique identification should be specified in encode().

    Declaration

    Swift

    class DynamicState<State> : Causality.AnyState<State> & Encodable where State : Equatable