Skip to content

Commit

Permalink
0.35.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dankinsoid committed Aug 27, 2024
1 parent b7bc4f4 commit bbff753
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ import PackageDescription
let package = Package(
name: "SomeProject",
dependencies: [
.package(url: "https://github.com/dankinsoid/VDStore.git", from: "0.34.0")
.package(url: "https://github.com/dankinsoid/VDStore.git", from: "0.35.0")
],
targets: [
.target(name: "SomeProject", dependencies: ["VDStore"])
Expand Down
2 changes: 1 addition & 1 deletion Sources/VDStore/Dependencies/CancellableStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension StoreDIValues {
@MainActor
final class CancellableStorage {

static let shared = CancellableStorage()
static nonisolated let shared = CancellableStorage()

var set: Set<AnyCancellable> = []

Expand Down
12 changes: 6 additions & 6 deletions Sources/VDStore/Utils/StoreBox.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Combine
@preconcurrency import Combine
import Foundation

struct StoreBox<Output>: Publisher {
struct StoreBox<Output>: Publisher, Sendable {

typealias Failure = Never

Expand All @@ -13,8 +13,8 @@ struct StoreBox<Output>: Publisher {
var willSet: AnyPublisher<Void, Never> { root.willSetPublisher }

private let root: StoreRootBoxType
private let getter: () -> Output
private let setter: (Output) -> Void
private let getter: @Sendable () -> Output
private let setter: @Sendable (Output) -> Void
private let valuePublisher: AnyPublisher<Output, Never>

init(_ value: Output) {
Expand Down Expand Up @@ -49,15 +49,15 @@ struct StoreBox<Output>: Publisher {
}
}

private protocol StoreRootBoxType {
private protocol StoreRootBoxType: Sendable {

var willSetPublisher: AnyPublisher<Void, Never> { get }
func startUpdate()
func endUpdate()
func forceUpdateIfNeeded()
}

private final class StoreRootBox<State>: StoreRootBoxType, Publisher {
private final class StoreRootBox<State>: StoreRootBoxType, Publisher, @unchecked Sendable {

typealias Output = State
typealias Failure = Never
Expand Down
23 changes: 11 additions & 12 deletions Tests/VDStoreTests/VDStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ import Combine
@testable import VDStore
import XCTest

@MainActor
final class VDStoreTests: XCTestCase {

/// Test that initializing a Store with a given state sets the initial state correctly.
func testInitialState() {
@MainActor func testInitialState() {
let initialCounter = Counter(counter: 10)
let store = Store(initialCounter)
XCTAssertEqual(store.state.counter, 10)
}

/// Test that a state mutation updates the state as expected.
func testStateMutation() {
@MainActor func testStateMutation() {
let store = Store(Counter())
store.add()

Expand Down Expand Up @@ -72,7 +71,7 @@ final class VDStoreTests: XCTestCase {
XCTAssertEqual(value, 6)
}

func testUpdate() {
@MainActor func testUpdate() {
let store = Store(Counter())
let publisher = store.publisher
var count = 0
Expand All @@ -91,7 +90,7 @@ final class VDStoreTests: XCTestCase {
}

/// Test that the publisher property of a Store sends updates when the state changes.
func testAsyncSequenceUpdates() async {
@MainActor func testAsyncSequenceUpdates() async {
let initialCounter = Counter(counter: 0)
let store = Store(initialCounter)
Task {
Expand All @@ -106,7 +105,7 @@ final class VDStoreTests: XCTestCase {

#if swift(>=5.9)
/// Test that the publisher property of a Store sends updates when the state changes.
func testPublisherUpdates() async {
@MainActor func testPublisherUpdates() async {
let initialCounter = Counter(counter: 0)
let store = Store(initialCounter)
let expectation = expectation(description: "State updated")
Expand All @@ -123,19 +122,19 @@ final class VDStoreTests: XCTestCase {
await fulfillment(of: [expectation], timeout: 0.1)
}

func testTasksMacroCancel() async {
@MainActor func testTasksMacroCancel() async {
let store = Store(Counter())
let value = await store.cancellableTask()
XCTAssertEqual(value, 6)
}

func testTaskMacroCancelInFlight() async {
@MainActor func testTaskMacroCancelInFlight() async {
let store = Store(Counter())
let value = await store.cancellableInFlightTask()
XCTAssertEqual(value, 6)
}

func testNumberOfUpdates() async {
@MainActor func testNumberOfUpdates() async {
let store = Store(Counter())
let publisher = store.publisher
var updatesCount = 0
Expand Down Expand Up @@ -164,7 +163,7 @@ final class VDStoreTests: XCTestCase {
XCTAssertEqual(updatesCount, 2)
}

func testOnChange() async {
@MainActor func testOnChange() async {
let expectation = expectation(description: "Counter")
let store = Store(Counter()).onChange(of: \.counter) { _, _, state in
state.counter += 1
Expand All @@ -177,7 +176,7 @@ final class VDStoreTests: XCTestCase {
XCTAssertEqual(store.state.counter, 2)
}

func testSyncUpdateInAsyncUpdate() async {
@MainActor func testSyncUpdateInAsyncUpdate() async {
let store = Store(Counter())
let publisher = store.publisher
var updatesCount = 0
Expand Down Expand Up @@ -210,7 +209,7 @@ final class VDStoreTests: XCTestCase {
XCTAssertEqual(updatesCount, 3)
}

func testAsyncUpdateInSyncUpdate() async {
@MainActor func testAsyncUpdateInSyncUpdate() async {
let store = Store(Counter())
let publisher = store.publisher
var updatesCount = 0
Expand Down

0 comments on commit bbff753

Please sign in to comment.