Skip to content

Commit 10580ff

Browse files
committed
Add shared bark instance, tests, and documentation.
1 parent 87697bb commit 10580ff

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Bark is available through the Swift Package Manager. To install it, simply add t
1919

2020
```swift
2121
dependencies: [
22-
.package(url: "https://github.com/willowtreeapps/bark.git", from: "1.0.1")
22+
.package(url: "https://github.com/willowtreeapps/bark.git", from: "1.0.2")
2323
]
2424
```
2525

@@ -31,7 +31,9 @@ Bark allows for structured concurrent message broadcasting. Here's an example fr
3131
```swift
3232
// Bark instance: I recommend registering into dependency injection and resolving it where you need it.
3333
// Consider [Grove](https://github.com/willowtreeapps/grove) for this purpose!
34-
// You normally want a single instance of Bark for your app.
34+
// 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.
35+
// The instance is similar in purpose to NotificationCenter instance.
36+
// If not using dependency injection, you can use `Bark.shared`. This is equivalent to NotificationCenter.default.
3537
let bark = Bark()
3638

3739
func testPostsOfASingleSubscription() async throws {

Sources/Bark/Bark.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ public final class Bark: @unchecked Sendable {
1111

1212
// MARK: - Types
1313

14+
/// The block that is invoked when a subscription receives a notification
1415
public typealias Block = (Any?) async -> Void
1516

17+
/// Notifications are identified by their name
1618
public struct Name: Hashable, Equatable {
1719
private let value: String
1820
public init(_ value: String) {
@@ -22,6 +24,8 @@ public final class Bark: @unchecked Sendable {
2224
public var description: String { value }
2325
}
2426

27+
/// 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.
28+
/// For example, you can create one Store per view (Make sure to mark it as @State if using SwiftUI)
2529
public final class Store: @unchecked Sendable {
2630
struct Handler {
2731
let name: Name
@@ -56,6 +60,7 @@ public final class Bark: @unchecked Sendable {
5660

5761
// MARK: - Properties
5862

63+
public static let shared = Bark()
5964
private let lock = NSLock()
6065
private struct StoreWrapper {
6166
weak var store: Store?

Tests/BarkTests/BarkTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import XCTest
1111

1212
final class BarkTests: XCTestCase {
1313
@MainActor
14-
let bark = Bark()
14+
let bark = Bark.shared
1515

1616
@MainActor
1717
override func setUp() async throws {}

0 commit comments

Comments
 (0)