EventsKit
Small Swift events kit that provides some base types of events:
FutureEventPresentEventPastEvent
Each this type may implement some Event protocols:
Eventit's a object that contains any listners (swift closures) with one template parameter - emited value type.EmptyEventit's syntactic sugar forEventwith Void template parameter.ValueEventit's event, that can contain only one listner and this listner should get and return value. This protocol contains contains two template parameters.
FutureEvent
Description
This is classic event (like C# event) that can contains many listners and multicast each new message for this listners.
This event emit only new messages. It means that if you add new listner to existed event this event doesn't emit previous messages to new listner.
Types
FutureEvent: EventFutureEmptyEvent: EmptyEventFutureValueEvent: ValueEvent
Example
var event = FutureEvent<Int>()
event += { value in
print("Awesome int: \(value)")
}
event.invoke(with: 42)
will print Awesome int: 42
PresentEvent
Description
This event provide all Future logic, but additionally provide emits last emited value for new listner.
It means if your event already emits value and you add new listener then yout listener handles previous emited value in the same time.
Types
PresentEvent: EventPresentEmptyEvent: EmptyEvent
Example
var event = FutureEvent<Int>()
event += { value in
print("Awesome int: \(value)")
}
event.invoke(with: 42)
event += {
print("Old awesome int: \(value)")
}
will print:
Awesome int: 42
Old awesome int: 42
PastEvent
Description
This event like Present, but emits all previous messages for new listner
Types
PastEvent: Event
Example
var event = FutureEvent<Int>()
event.invoke(with: 0)
event.invoke(with: 1)
event += { value in
print("Awesome int: \(value)")
}
event.invoke(with: 2)
Will print:
Awesome int: 0
Awesome int: 1
Awesome int: 2
How to install
pod 'EventsKit', '~> 1.0.0'