Skip to content

Commit f5dc426

Browse files
committed
Doc Comment Improvements
preparing for a v1 release, so need to ensure the doc comments are solid.
1 parent 29bece7 commit f5dc426

File tree

4 files changed

+53
-32
lines changed

4 files changed

+53
-32
lines changed

Sources/EventDrivenSwift/Central/EventCentral.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import Foundation
1212
Singleton for the Central Event Handler.
1313
- Author: Simon J. Stuart
1414
- Version: 1.0.0
15-
to access the Central Event Handler.
1615
- Note: This is a Singleton!
1716
- Note: This is used when invoking the `queue` and `stack` methods of `Eventable`.
1817
*/
@@ -26,6 +25,4 @@ final public class EventCentral: EventDispatcher {
2625
}
2726

2827
override private init() {}
29-
30-
3128
}

Sources/EventDrivenSwift/EventDispatcher/EventDispatcher.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ import Foundation
1010
import ThreadSafeSwift
1111
import Observable
1212

13-
public class EventDispatcher: EventHandler, EventDispatchable {
13+
/**
14+
An implementation of `EventHandler` designed to Queue/Stack outbound events, and Dispatch them to all registered `listeners`
15+
- Author: Simon J. Stuart
16+
- Version: 1.0.0
17+
- Note: While you can inherit from and even create instances of `EventDispatcher`, best practice would be to use `EventCentral.shared` as the central Event Dispatcher.
18+
*/
19+
open class EventDispatcher: EventHandler, EventDispatchable {
1420
struct ListenerContainer {
1521
weak var listener: (any EventReceivable)?
1622
}

Sources/EventDrivenSwift/EventHandler/EventHandler.swift

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ import Foundation
1010
import ThreadSafeSwift
1111
import Observable
1212

13+
/**
14+
Abstract Base Type for all `EventHandler` Thread Types.
15+
- Author: Simon J. Stuart
16+
- Version: 1.0.0
17+
- Note: This is the Common Base Type for `EventDispatcher` and `EventReceiver` base types
18+
*/
1319
open class EventHandler: ObservableThread, EventHandlable {
1420
/**
1521
A Map of `EventPriority` against an Array of `Eventable` in that corresponding Queue
@@ -37,25 +43,26 @@ open class EventHandler: ObservableThread, EventHandlable {
3743
var stackCount: Int = 0
3844
var queueCount: Int = 0
3945

40-
var snapStacks = [EventPriority:[any Eventable]]()
41-
var snapQueues = [EventPriority:[any Eventable]]()
46+
var snapStacks = [EventPriority:[any Eventable]]() // Snapshot of the current Stacks
47+
var snapQueues = [EventPriority:[any Eventable]]() // Snapshot of hte current Queues
4248

43-
_stacks.withLock { stacks in
44-
snapStacks = stacks
45-
}
46-
_queues.withLock { queues in
47-
snapQueues = queues
48-
}
49+
_stacks.withLock { stacks in // With the Lock
50+
snapStacks = stacks // Grab a Snapshot
51+
} // Lock releases
4952

50-
for stack in snapStacks.values {
51-
stackCount += stack.count
53+
_queues.withLock { queues in // With the Lock
54+
snapQueues = queues // Grab a Snapshot
55+
} // Lock releases
56+
57+
for stack in snapStacks.values { // Iterate Stacks
58+
stackCount += stack.count // Increment Count
5259
}
5360

54-
for queue in snapQueues.values {
55-
queueCount += queue.count
61+
for queue in snapQueues.values { // Iterate Queues
62+
queueCount += queue.count // Increment Count
5663
}
5764

58-
return stackCount + queueCount
65+
return stackCount + queueCount // Return the sum of Stack and Queue counts (total Event Count)
5966
}
6067
}
6168

@@ -146,6 +153,11 @@ open class EventHandler: ObservableThread, EventHandlable {
146153
}
147154
}
148155

156+
/**
157+
Simple Macro to process first the Stacks, then the Queues
158+
- Author: Simon J. Stuart
159+
- Version: 1.0.0
160+
*/
149161
internal func processAllEvents() {
150162
processEventStacks() // we process Stacks first
151163
processEventQueues() // we process Queues next

Sources/EventDrivenSwift/EventReceiver/EventReceiver.swift

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ import Foundation
1010
import ThreadSafeSwift
1111
import Observable
1212

13-
public class EventReceiver: EventHandler, EventReceivable {
13+
/**
14+
Abstract Base Type for all `EventRecevier` Thread Types.
15+
- Author: Simon J. Stuart
16+
- Version: 1.0.0
17+
- Note: Inherit from this to implement a discrete unit of code designed specifically to operate upon specific `Eventable` types containing information useful to its operation(s)
18+
*/
19+
open class EventReceiver: EventHandler, EventReceivable {
1420
/**
1521
Convienience `typealias` used for Event Callbacks
1622
- Author: Simon J. Stuart
@@ -33,8 +39,6 @@ public class EventReceiver: EventHandler, EventReceivable {
3339
*/
3440
@ThreadSafeSemaphore private var eventCallbacks = [String:EventCallback]() //TODO: Make this a Revolving Door collection!
3541

36-
// @ThreadSafeSemaphore private var typedEventCallbacks = [String:Any]() //TODO: Find an implementation that works for strong-typed Event Callbacks (P.S. limitations of Swift Generics are very annoying!)
37-
3842
/**
3943
Invoke the appropriate Callback for the given Event
4044
- Author: Simon J. Stuart
@@ -72,24 +76,21 @@ public class EventReceiver: EventHandler, EventReceivable {
7276
EventCentral.shared.addListener(self, forEventType: forEventType)
7377
}
7478

79+
/**
80+
Performs a Transparent Type Test, Type Cast, and Method Call via the `callback` Closure.
81+
- Author: Simon J. Stuart
82+
- Version: 1.0.0
83+
- Parameters:
84+
- callback: The code (Closure or Callback Method) to execute for the given `forEvent`, typed generically using `TEvent`
85+
- forEvent: The instance of the `Eventable` type to be processed
86+
- priority: The `EventPriority` with which the `forEvent` was dispatched
87+
*/
7588
internal func callTypedEventCallback<TEvent: Eventable>(_ callback: @escaping TypedEventCallback<TEvent>, forEvent: Eventable, priority: EventPriority) {
7689
if let typedEvent = forEvent as? TEvent {
7790
callback(typedEvent, priority)
7891
}
7992
}
8093

81-
//TODO: Find an implementation that works for strong-typed Event Callbacks (P.S. limitations of Swift Generics are very annoying!)
82-
// internal func addEventCallback<TEvent: Eventable>(_ callback: @escaping TypedEventCallback<TEvent>, forEventType: Eventable.Type) {
83-
// let eventTypeName = String(reflecting: forEventType)
84-
//
85-
// _typedEventCallbacks.withLock { typedEventCallbacks in
86-
// typedEventCallbacks[eventTypeName] = callback
87-
// }
88-
//
89-
// /// We automatically register the Listener with the Central Event Dispatcher
90-
// EventCentral.shared.addListener(self, forEventType: forEventType)
91-
// }
92-
9394
/**
9495
Removes an Event Callback for the given `Eventable` Type
9596
- Author: Simon J. Stuart
@@ -114,6 +115,11 @@ public class EventReceiver: EventHandler, EventReceivable {
114115
// No default implementation
115116
}
116117

118+
/**
119+
Initializes an `EventReciever` decendant and invokes `registerEventListeners()` to register your Event Listeners within your `EventReceiver` type.
120+
- Author: Simon J. Stuart
121+
- Version: 1.0.0
122+
*/
117123
override init() {
118124
super.init()
119125
registerEventListeners()

0 commit comments

Comments
 (0)