From 87697bbcb7fd849196ff03623f59aaeed9ced685 Mon Sep 17 00:00:00 2001 From: Raf Date: Wed, 3 Jul 2024 10:33:27 -0400 Subject: [PATCH 1/3] Small update to the readme for clarity. --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 56979a8..3c096d5 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Bark -Simple message broadcasting library (similar to NotificationCenter in spirit). It's designed to help you manage a group of dependencies in a container, and easily resolve them when needed, thus helping make your project more modular, testable, and maintainable. +Simple, but powerful, message broadcasting library (similar to NotificationCenter in spirit). -Tree bark won't bark. But `bark` will, and it will allow you to broadcast information across your app in a structured concurrent way. +Tree bark won't bark. But `bark` will!, and it will help you broadcast information across your app in a structured concurrent way. ## Why Bark With `bark`, you can register subscriptions that require a concurrency context, and be assured at the point of use that the subscription was run when the `await` to the associated post completes. @@ -29,6 +29,11 @@ Bark allows for structured concurrent message broadcasting. Here's an example fr ### Registration ```swift +// Bark instance: I recommend registering into dependency injection and resolving it where you need it. +// Consider [Grove](https://github.com/willowtreeapps/grove) for this purpose! +// You normally want a single instance of Bark for your app. +let bark = Bark() + func testPostsOfASingleSubscription() async throws { // Given let subscriptions = Bark.Store() From 432f792c9079d4b29bfb037638f6affa7729d98b Mon Sep 17 00:00:00 2001 From: Raf Date: Mon, 2 Sep 2024 22:35:57 -0400 Subject: [PATCH 2/3] Add shared bark instance, tests, and documentation. --- README.md | 12 +++++++++--- Sources/Bark/Bark.swift | 5 +++++ Tests/BarkTests/BarkTests.swift | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3c096d5..ac9c87c 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Bark is available through the Swift Package Manager. To install it, simply add t ```swift dependencies: [ - .package(url: "https://github.com/willowtreeapps/bark.git", from: "1.0.1") + .package(url: "https://github.com/willowtreeapps/bark.git", from: "1.0.2") ] ``` @@ -29,9 +29,15 @@ Bark allows for structured concurrent message broadcasting. Here's an example fr ### Registration ```swift -// Bark instance: I recommend registering into dependency injection and resolving it where you need it. +// Bark instance: I recommend registering into dependency injection and resolving it +// where you need it. // Consider [Grove](https://github.com/willowtreeapps/grove) for this purpose! -// You normally want a single instance of Bark for your app. +// +// You normally want a single instance of Bark for your app, but you can define +// different instances that deal with different parts of the app. +// The instance is similar in purpose to NotificationCenter instance. +// If not using dependency injection, you can use `Bark.shared`. This is equivalent +// to NotificationCenter.default. let bark = Bark() func testPostsOfASingleSubscription() async throws { diff --git a/Sources/Bark/Bark.swift b/Sources/Bark/Bark.swift index 64dd3b8..8f2c430 100644 --- a/Sources/Bark/Bark.swift +++ b/Sources/Bark/Bark.swift @@ -11,8 +11,10 @@ public final class Bark: @unchecked Sendable { // MARK: - Types + /// The block that is invoked when a subscription receives a notification public typealias Block = (Any?) async -> Void + /// Notifications are identified by their name public struct Name: Hashable, Equatable { private let value: String public init(_ value: String) { @@ -22,6 +24,8 @@ public final class Bark: @unchecked Sendable { public var description: String { value } } + /// Subscriptions are scoped to a store. Create a store in a place where the store's lifetime will match when the subscription needs to be handled. + /// For example, you can create one Store per view (Make sure to mark it as @State if using SwiftUI) public final class Store: @unchecked Sendable { struct Handler { let name: Name @@ -56,6 +60,7 @@ public final class Bark: @unchecked Sendable { // MARK: - Properties + public static let shared = Bark() private let lock = NSLock() private struct StoreWrapper { weak var store: Store? diff --git a/Tests/BarkTests/BarkTests.swift b/Tests/BarkTests/BarkTests.swift index 13695e8..f7500b8 100644 --- a/Tests/BarkTests/BarkTests.swift +++ b/Tests/BarkTests/BarkTests.swift @@ -11,7 +11,7 @@ import XCTest final class BarkTests: XCTestCase { @MainActor - let bark = Bark() + let bark = Bark.shared @MainActor override func setUp() async throws {} From b60b162e9b8132d457854d7df295f8f0a49a94fd Mon Sep 17 00:00:00 2001 From: Raf Date: Thu, 2 Jan 2025 22:07:10 -0500 Subject: [PATCH 3/3] Support iOS / tvOS 15 --- Package.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Package.swift b/Package.swift index a2300c6..7a93d3c 100644 --- a/Package.swift +++ b/Package.swift @@ -6,8 +6,8 @@ import PackageDescription let package = Package( name: "Bark", platforms: [ - .iOS(.v16), - .tvOS(.v16), + .iOS(.v15), + .tvOS(.v15), .watchOS(.v5), .visionOS(.v1), ],