Event
public final class Event<T>
A simple EventType implementation.
-
The current state of the event.
Declaration
Swift
fileprivate (set) public var state = EventState<T>.active
-
Returns
true
if the event state isClosed
.Declaration
Swift
public var closed: Bool
-
Notifies observers.
If the event has been closed, this has no effect.
Declaration
Swift
public func fire(_ payload: T)
Parameters
payload
A value to be passed to each observer.
-
Closes the event.
If the event has already been closed, this has no effect.
Calls all observers with the given payload. Once an event is closed, calling
fire(payload:)
orclose(payload:)
will have no effect. Adding an observer after an event is closed will simply call the observer synchronously with the payload that the event was closed with.Declaration
Swift
public func close(_ payload: T)
-
Adds an observer.
Adding an observer after an event is closed will simply call the observer synchronously with the payload that the event was closed with.
Declaration
Swift
public func observe(_ observer: @escaping Observer)
Parameters
observer
A closure that will be executed when this event is fired.
-
Adds an observer for a key.
Adding an observer after an event is closed will simply call the observer synchronously with the payload that the event was closed with.
See also
func unobserve(key:)Declaration
Swift
public func observe(_ observer: @escaping Observer, key: String)
Parameters
observer
A closure that will be executed when this event is fired.
key
A string that identifies this observer, which can be used to remove the observer.
-
Removed an observer with a given key.
See also
func observe(observer:key:)Declaration
Swift
public func unobserve(_ key: String)
Parameters
key
A string that identifies the observer to be removed. If an observer does not exist for the given key, the method returns without impact.