Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii committed Sep 18, 2024
1 parent d452fac commit d080085
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Sources/Verge/Store/DetachedDispatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public final class DetachedDispatcher<State: Equatable, Activity, Scope: Equatab
{

public let store: Store<State, Activity>
public let scope: WritableKeyPath<State, Scope>
public let scope: WritableKeyPath<State, Scope> & Sendable

init(
store: Store<State, Activity>,
scope: WritableKeyPath<State, Scope>
scope: WritableKeyPath<State, Scope> & Sendable
) {
self.store = store
self.scope = scope
Expand Down
4 changes: 2 additions & 2 deletions Sources/Verge/Store/Scan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

import Foundation

public final class Scan<Element, Accumulate> {
public final class Scan<Element, Accumulate>: Sendable {

public typealias Accumulator = (inout Accumulate, Element) -> Void
public typealias Accumulator = @Sendable (inout Accumulate, Element) -> Void

public var value: Accumulate {
_value.value
Expand Down
8 changes: 4 additions & 4 deletions Sources/Verge/Store/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ actor Writer {
/// ```
/// You may use also `StoreWrapperType` to define State and Activity as inner types.
///
open class Store<State: Equatable, Activity>: EventEmitter<_StoreEvent<State, Activity>>, CustomReflectable, StoreType, StoreDriverType, DerivedMaking, @unchecked Sendable {
open class Store<State: Equatable, Activity: Sendable>: EventEmitter<_StoreEvent<State, Activity>>, CustomReflectable, StoreType, StoreDriverType, DerivedMaking, @unchecked Sendable {

public var scope: WritableKeyPath<State, State> = \State.self
public var scope: WritableKeyPath<State, State> & Sendable = \State.self

private let tracker = VergeConcurrency.SynchronizationTracker()

Expand Down Expand Up @@ -772,7 +772,7 @@ Latest Version (%d): (%@)
scan: Scan<Changes<State>, Accumulate>,
dropsFirst: Bool = false,
queue: some TargetQueueType,
receive: @escaping (Changes<State>, Accumulate) -> Void
receive: @escaping @Sendable (Changes<State>, Accumulate) -> Void
) -> StoreStateSubscription {

_primitive_sinkState(dropsFirst: dropsFirst, queue: queue) { (changes) in
Expand All @@ -784,7 +784,7 @@ Latest Version (%d): (%@)
}

func _mainActor_sinkActivity(
queue: MainActorTargetQueue,
queue: some MainActorTargetQueueType,
receive: @escaping @MainActor (sending Activity) -> Void
) -> StoreActivitySubscription {
return _primitive_sinkActivity(
Expand Down
28 changes: 16 additions & 12 deletions Sources/Verge/Store/StoreDriverType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,15 @@ public protocol StoreDriverType<Scope>: ObservableObject where Activity == Targe

associatedtype TargetStore: StoreType


associatedtype Scope: Equatable = TargetStore.State

var store: TargetStore { get }
var scope: WritableKeyPath<TargetStore.State, Scope> { get }
var scope: WritableKeyPath<TargetStore.State, Scope> & Sendable { get }

var state: Changes<Scope> { get }

// WORKAROUND: for activityPublisher()
associatedtype Activity = TargetStore.Activity
associatedtype Activity: Sendable = TargetStore.Activity
}

extension StoreDriverType {
Expand Down Expand Up @@ -141,9 +140,14 @@ extension StoreDriverType where Scope == TargetStore.State {
scan: Scan<Changes<TargetStore.State>, Accumulate>,
dropsFirst: Bool = false,
queue: some TargetQueueType,
receive: @escaping (Changes<TargetStore.State>, Accumulate) -> Void
receive: @escaping @Sendable (Changes<TargetStore.State>, Accumulate) -> Void
) -> StoreStateSubscription {
store.asStore()._primitive_scan_sinkState(scan: scan, dropsFirst: dropsFirst, queue: queue, receive: receive)
store.asStore()._primitive_scan_sinkState(
scan: scan,
dropsFirst: dropsFirst,
queue: queue,
receive: receive
)
}

/// Subscribe the state changes
Expand Down Expand Up @@ -171,7 +175,7 @@ extension StoreDriverType where Scope == TargetStore.State {
@_disfavoredOverload
public func sinkActivity(
queue: some TargetQueueType,
receive: @escaping (TargetStore.Activity) -> Void
receive: @escaping @Sendable (sending TargetStore.Activity) -> Void
) -> StoreActivitySubscription {

store.asStore()._primitive_sinkActivity(queue: queue, receive: receive)
Expand All @@ -183,11 +187,11 @@ extension StoreDriverType where Scope == TargetStore.State {
/// - Returns: A subscriber that performs the provided closure upon receiving values.
public func sinkActivity(
queue: some MainActorTargetQueueType = .mainIsolated(),
receive: @escaping @MainActor (TargetStore.Activity) -> Void
receive: @escaping @MainActor (sending TargetStore.Activity) -> Void
) -> StoreActivitySubscription {

store.asStore()._mainActor_sinkActivity(queue: queue) { activity in
thunkToMainActor {
MainActor.assumeIsolated {
receive(activity)
}
}
Expand Down Expand Up @@ -225,7 +229,7 @@ extension StoreDriverType {
public func sinkState(
dropsFirst: Bool = false,
queue: some TargetQueueType,
receive: @escaping (Changes<Scope>) -> Void
receive: @escaping @Sendable (Changes<Scope>) -> Void
) -> StoreStateSubscription {
let _scope = scope

Expand Down Expand Up @@ -271,7 +275,7 @@ extension StoreDriverType {
scan: Scan<Changes<Scope>, Accumulate>,
dropsFirst: Bool = false,
queue: some TargetQueueType,
receive: @escaping (Changes<Scope>, Accumulate) -> Void
receive: @escaping @Sendable (Changes<Scope>, Accumulate) -> Void
) -> StoreStateSubscription {
sinkState(dropsFirst: dropsFirst, queue: queue) { (changes) in
let accumulate = scan.accumulate(changes)
Expand Down Expand Up @@ -514,12 +518,12 @@ extension StoreDriverType {
return result
}

public func detached<NewScope: Equatable>(from newScope: WritableKeyPath<TargetStore.State, NewScope>)
public func detached<NewScope: Equatable>(from newScope: WritableKeyPath<TargetStore.State, NewScope> & Sendable)
-> DetachedDispatcher<TargetStore.State, TargetStore.Activity, NewScope> {
.init(store: store.asStore(), scope: newScope)
}

public func detached<NewScope: Equatable>(by appendingScope: WritableKeyPath<Scope, NewScope>)
public func detached<NewScope: Equatable>(by appendingScope: WritableKeyPath<Scope, NewScope> & Sendable)
-> DetachedDispatcher<TargetStore.State, TargetStore.Activity, NewScope> {
.init(store: store.asStore(), scope: scope.appending(path: appendingScope))
}
Expand Down

0 comments on commit d080085

Please sign in to comment.