Skip to content

Commit e089c37

Browse files
committed
Close to v1.0.0 release-ready
All of the fundamentals are implemented, tested, and working. - Some Thread-Safety improvements will be performed on `queue` and `stack` and `listener` collections similar to those made in the Observable library
1 parent fbec556 commit e089c37

File tree

16 files changed

+1155
-0
lines changed

16 files changed

+1155
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,6 @@ fastlane/test_output
8888
# https://github.com/johnno1962/injectionforxcode
8989

9090
iOSInjectionProject/
91+
92+
# MacOS FileSystem
93+
*.DS_Store

.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.resolved

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// swift-tools-version: 5.7
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "EventDrivenSwift",
8+
platforms: [
9+
.macOS(.v10_15),
10+
.iOS(.v13),
11+
.tvOS(.v13),
12+
.watchOS(.v6)
13+
],
14+
products: [
15+
// Products define the executables and libraries a package produces, and make them visible to other packages.
16+
.library(
17+
name: "EventDrivenSwift",
18+
targets: ["EventDrivenSwift"]),
19+
],
20+
dependencies: [
21+
// Dependencies declare other packages that this package depends on.
22+
.package(url: "https://github.com/Flowduino/ThreadSafeSwift.git", .upToNextMajor(from: "1.1.0")),
23+
.package(url: "https://github.com/Flowduino/Observable.git", .upToNextMajor(from: "1.1.0")),
24+
],
25+
targets: [
26+
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
27+
// Targets can depend on other targets in this package, and on products in packages this package depends on.
28+
.target(
29+
name: "EventDrivenSwift",
30+
dependencies: [
31+
.product(name: "ThreadSafeSwift", package: "ThreadSafeSwift"),
32+
.product(name: "Observable", package: "Observable"),
33+
]
34+
),
35+
.testTarget(
36+
name: "EventDrivenSwiftTests",
37+
dependencies: [
38+
"EventDrivenSwift",
39+
.product(name: "ThreadSafeSwift", package: "ThreadSafeSwift"),
40+
.product(name: "Observable", package: "Observable"),
41+
]),
42+
]
43+
)

README.md

Lines changed: 363 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// EventCentral.swift
3+
// Copyright (c) 2022, Flowduino
4+
// Authored by Simon J. Stuart on 4th August 2022
5+
//
6+
// Subject to terms, restrictions, and liability waiver of the MIT License
7+
//
8+
9+
import Foundation
10+
11+
/**
12+
Singleton for the Central Event Handler.
13+
- Author: Simon J. Stuart
14+
- Version: 1.0.0
15+
to access the Central Event Handler.
16+
- Note: This is a Singleton!
17+
- Note: This is used when invoking the `queue` and `stack` methods of `Eventable`.
18+
*/
19+
final public class EventCentral: EventDispatcher {
20+
private static var _shared: EventDispatcher = EventCentral()
21+
22+
public static var shared: EventDispatchable {
23+
get {
24+
return _shared
25+
}
26+
}
27+
28+
override private init() {}
29+
30+
31+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// EventDispatchMethod.swift
3+
// Copyright (c) 2022, Flowduino
4+
// Authored by Simon J. Stuart on 4th August 2022
5+
//
6+
// Subject to terms, restrictions, and liability waiver of the MIT License
7+
//
8+
9+
import Foundation
10+
11+
/**
12+
Specifies the Dispatch Method of a given Event
13+
- Author: Simon J. Stuart
14+
- Version: 1.0.0
15+
*/
16+
public enum EventDispatchMethod: CaseIterable {
17+
/// The Event was dispatched through the Queue
18+
case queue
19+
/// The Event was dispatched through the Stack
20+
case stack
21+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// EventPriority.swift
3+
// Copyright (c) 2022, Flowduino
4+
// Authored by Simon J. Stuart on 4th August 2022
5+
//
6+
// Subject to terms, restrictions, and liability waiver of the MIT License
7+
//
8+
9+
import Foundation
10+
11+
/**
12+
Specifies the Priority of a given Event
13+
- Author: Simon J. Stuart
14+
- Version: 1.0.0
15+
*/
16+
public enum EventPriority: CaseIterable {
17+
case lowest
18+
case low
19+
case normal
20+
case high
21+
case highest
22+
23+
/**
24+
Returns all of the `EventPriority` cases in order of `highest` to `lowest` (reverse order).
25+
- Author: Simon J. Stuart
26+
- Version: 1.0.0
27+
- Note: This is necessary because we always process Events in priority-order from `highest` to `lowest`
28+
*/
29+
public static let inOrder = Self.allCases.reversed()
30+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//
2+
// Eventable.swift
3+
// Copyright (c) 2022, Flowduino
4+
// Authored by Simon J. Stuart on 4th August 2022
5+
//
6+
// Subject to terms, restrictions, and liability waiver of the MIT License
7+
//
8+
9+
import Foundation
10+
11+
/**
12+
Protocol describing anything that can be dispatched as an Event
13+
- Author: Simon J. Stuart
14+
- Version: 1.0.0
15+
- Note: You should **never** pass any `class` instance references along in an `Eventable` type.
16+
- Note: `Eventable` types **must** always be **immutable**
17+
*/
18+
public protocol Eventable {
19+
/**
20+
Dispatch the Event to the Central Queue with the given `priority`
21+
- Author: Simon J. Stuart
22+
- Version: 1.0.0
23+
- Parameters:
24+
- priority: The Priority with which to process this Event
25+
*/
26+
func queue(priority: EventPriority)
27+
28+
/**
29+
Dispatch the Event to the Central Stack with the given `priority`
30+
- Author: Simon J. Stuart
31+
- Version: 1.0.0
32+
- Parameters:
33+
- priority: The Priority with which to process this Event
34+
*/
35+
func stack(priority: EventPriority)
36+
}
37+
38+
/**
39+
Extension to provide Operator Overrides for `Eventable` types
40+
- Author: Simon J. Stuart
41+
- Version: 1.0.0
42+
*/
43+
extension Eventable {
44+
static func == (lhs: Self, rhs: Self) -> Bool {
45+
return String(reflecting: lhs) == String(reflecting: rhs)
46+
}
47+
}
48+
49+
/**
50+
Extension to provide transparent `queue` and `stack` dispatch via `EventCentral`
51+
- Author: Simon J. Stuart
52+
- Version: 1.0.0
53+
*/
54+
extension Eventable {
55+
public func queue(priority: EventPriority = .normal) {
56+
EventCentral.shared.queueEvent(self, priority: priority)
57+
}
58+
59+
public func stack(priority: EventPriority = .normal) {
60+
EventCentral.shared.stackEvent(self, priority: priority)
61+
}
62+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// EventDispatchable.swift
3+
// Copyright (c) 2022, Flowduino
4+
// Authored by Simon J. Stuart on 4th August 2022
5+
//
6+
// Subject to terms, restrictions, and liability waiver of the MIT License
7+
//
8+
9+
import Foundation
10+
11+
/**
12+
Protocol describing anything that Dispatches Events
13+
- Author: Simon J. Stuart
14+
- Version: 1.0.0
15+
*/
16+
public protocol EventDispatchable: EventHandlable {
17+
/**
18+
Registers the given `listener` for the given `Eventable` Type
19+
- Author: Simon J. Stuart
20+
- Version: 1.0.0
21+
*/
22+
func addListener(_ listener: any EventReceivable, forEventType: Eventable.Type)
23+
24+
/**
25+
Unregisters the given `listener` from the given `Eventable` Type
26+
- Author: Simon J. Stuart
27+
- Version: 1.0.0
28+
*/
29+
func removeListener(_ listener: any EventReceivable, forEventType: Eventable.Type)
30+
31+
/**
32+
Unregisters the given `listener` from all `Eventable` Types
33+
- Author: Simon J. Stuart
34+
- Version: 1.0.0
35+
*/
36+
func removeListener(_ listener: any EventReceivable)
37+
}

0 commit comments

Comments
 (0)