Skip to content

Commit

Permalink
Update protocols (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii committed Mar 17, 2023
1 parent a634b80 commit 1f528bf
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 33 deletions.
10 changes: 5 additions & 5 deletions Sources/Verge/Derived/Derived+Assign.swift
Expand Up @@ -30,7 +30,7 @@ extension Derived {
queue: TargetQueue = .passthrough,
to binder: @escaping (Changes<Value>) -> Void
) -> VergeAnyCancellable {
sinkValue(queue: queue, receive: binder)
sinkState(queue: queue, receive: binder)
}

/**
Expand All @@ -42,11 +42,11 @@ extension Derived {
queue: MainActorTargetQueue,
to binder: @escaping (Changes<Value>) -> Void
) -> VergeAnyCancellable {
sinkValue(queue: queue, receive: binder)
sinkState(queue: queue, receive: binder)
}
}

extension StoreType {
extension DispatcherType {

/**
Assigns a Store's state to a property of a store.
Expand All @@ -57,7 +57,7 @@ extension StoreType {
queue: TargetQueue = .passthrough,
to binder: @escaping (Changes<State>) -> Void
) -> VergeAnyCancellable {
asStore().sinkState(queue: queue, receive: binder)
store.asStore().sinkState(queue: queue, receive: binder)
}

/**
Expand All @@ -69,7 +69,7 @@ extension StoreType {
queue: MainActorTargetQueue,
to binder: @escaping (Changes<State>) -> Void
) -> VergeAnyCancellable {
asStore().sinkState(queue: queue, receive: binder)
store.asStore().sinkState(queue: queue, receive: binder)
}

}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Verge/Store/DispatcherType.swift
Expand Up @@ -22,7 +22,7 @@
import Foundation

// It would be renamed as StoreContextType
public protocol DispatcherType {
public protocol DispatcherType: AnyObject {
associatedtype WrappedStore: StoreType
associatedtype Scope: Equatable = WrappedStore.State

Expand Down
14 changes: 7 additions & 7 deletions Sources/Verge/Store/StoreType+Assignee.swift
Expand Up @@ -21,7 +21,7 @@

import Foundation

extension StoreType {
extension DispatcherType {

public typealias Assignee<Value> = (Value) -> Void

Expand All @@ -43,7 +43,7 @@ extension StoreType {
) -> Assignee<Changes<Value>> {
return { [weak self] value in
guard !dropsOutput(value) else { return }
self?.asStore().commit {
self?.store.asStore().commit {
$0[keyPath: keyPath] = value.primitive
}
}
Expand All @@ -67,7 +67,7 @@ extension StoreType {
) -> Assignee<Changes<Value?>> {
return { [weak self] value in
guard !dropsOutput(value) else { return }
self?.asStore().commit {
self?.store.asStore().commit {
$0[keyPath: keyPath] = value.primitive
}
}
Expand All @@ -92,7 +92,7 @@ extension StoreType {
return { [weak self] value in
let changes = value.map { Optional.some($0) }
guard !dropsOutput(changes) else { return }
self?.asStore().commit {
self?.store.asStore().commit {
$0[keyPath: keyPath] = .some(value.primitive)
}
}
Expand All @@ -105,7 +105,7 @@ extension StoreType {
_ keyPath: WritableKeyPath<State, Value>
) -> Assignee<Value> {
return { [weak self] value in
self?.asStore().commit {
self?.store.asStore().commit {
$0[keyPath: keyPath] = value
}
}
Expand All @@ -118,7 +118,7 @@ extension StoreType {
_ keyPath: WritableKeyPath<State, Value?>
) -> Assignee<Value?> {
return { [weak self] value in
self?.asStore().commit {
self?.store.asStore().commit {
$0[keyPath: keyPath] = value
}
}
Expand All @@ -131,7 +131,7 @@ extension StoreType {
_ keyPath: WritableKeyPath<State, Value?>
) -> Assignee<Value> {
return { [weak self] value in
self?.asStore().commit {
self?.store.asStore().commit {
$0[keyPath: keyPath] = .some(value)
}
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/Verge/Store/StoreType+BindingDerived.swift
Expand Up @@ -21,7 +21,7 @@

import class Foundation.NSString

extension StoreType {
extension DispatcherType {

/// Returns Binding Derived object
///
Expand All @@ -45,13 +45,13 @@ extension StoreType {
let derived = BindingDerived<Pipeline.Output>.init(
get: pipeline,
set: { [weak self] state in
self?.asStore().commit(name, file, function, line) {
self?.store.asStore().commit(name, file, function, line) {
set(&$0, state)
}
},
initialUpstreamState: asStore().state,
initialUpstreamState: store.asStore().state,
subscribeUpstreamState: { callback in
asStore()._primitive_sinkState(
store.asStore()._primitive_sinkState(
dropsFirst: true,
queue: queue,
receive: callback
Expand Down
6 changes: 3 additions & 3 deletions Sources/Verge/Store/StoreType+Derived.swift
Expand Up @@ -21,7 +21,7 @@

import class Foundation.NSString

extension StoreType {
extension DispatcherType {

public func derived<Pipeline: PipelineType>(
_ pipeline: Pipeline,
Expand All @@ -35,9 +35,9 @@ extension StoreType {
set: { _ in

},
initialUpstreamState: asStore().state,
initialUpstreamState: store.asStore().state,
subscribeUpstreamState: { callback in
asStore()._primitive_sinkState(dropsFirst: true, queue: queue, receive: callback)
store.asStore()._primitive_sinkState(dropsFirst: true, queue: queue, receive: callback)
},
retainsUpstream: nil
)
Expand Down
4 changes: 2 additions & 2 deletions Sources/Verge/SwiftUI/StoreReader.swift
Expand Up @@ -36,13 +36,13 @@ public struct StoreReader<StateType: Equatable, Content: View>: View {
/// - Parameters:
/// - store:
/// - content:
public init<Store: StoreType>(
public init<Store: DispatcherType>(
debug: Bool = false,
_ store: Store,
@ViewBuilder content: @escaping ContentMaker
) where StateType == Store.State {

let store = store.asStore()
let store = store.store.asStore()

self.init(node: .init(store: store, retainValues: [], debug: debug), content: content)

Expand Down
12 changes: 6 additions & 6 deletions Sources/VergeORM/Derived+ORM.swift
Expand Up @@ -169,7 +169,7 @@ public typealias NonNullDerivedResult<Entity: EntityType> = DerivedResult<Entity
fileprivate var _derivedContainerAssociated: Void?
fileprivate var _nonnull_derivedContainerAssociated: Void?

extension StoreType {
extension DispatcherType {

private var _nonatomic_derivedObjectCache: _DerivedObjectCache {

Expand Down Expand Up @@ -241,7 +241,7 @@ public struct DatabaseContext<Store: StoreType, Database: DatabaseType> {
}

@dynamicMemberLookup
public struct DatabaseDynamicMembers<Store: StoreType> {
public struct DatabaseDynamicMembers<Store: DispatcherType> {

unowned let store: Store

Expand All @@ -255,7 +255,7 @@ public struct DatabaseDynamicMembers<Store: StoreType> {

}

extension StoreType {
extension DispatcherType {

/**
A cushion for databases. the return object has properties to databases.
Expand Down Expand Up @@ -368,7 +368,7 @@ extension DatabaseContext {
from entityID: Entity.EntityID,
queue: TargetQueueType = .passthrough
) -> Entity.Derived {
store.derivedEntity(entityID: entityID, from: keyPath)
store.asStore().derivedEntity(entityID: entityID, from: keyPath)
}

// MARK: - Convenience operators
Expand All @@ -378,7 +378,7 @@ extension DatabaseContext {
from entity: Entity,
queue: TargetQueueType = .passthrough
) -> Entity.NonNullDerived {
store.derivedEntityPersistent(entity: entity, from: keyPath)
store.asStore().derivedEntityPersistent(entity: entity, from: keyPath)
}

/// Returns a derived object that provides a concrete entity according to the updating source state
Expand Down Expand Up @@ -548,7 +548,7 @@ extension DatabaseContext {
queue: TargetQueueType = .passthrough
) -> Derived<[Entity.Derived]> {

return store.derived(
return store.asStore().derived(
_DatabaseMultipleEntityPipeline(
keyPathToDatabase: keyPath,
index: ids,
Expand Down
10 changes: 5 additions & 5 deletions Sources/VergeRx/Store+Rx.swift
Expand Up @@ -299,15 +299,15 @@ extension ReadonlyStorage {

}

extension Reactive where Base : StoreType {
extension Reactive where Base : DispatcherType {

public func commitBinder<S>(
scheduler: ImmediateSchedulerType = MainScheduler(),
mutate: @escaping (inout InoutRef<Base.State>, S) -> Void
) -> Binder<S> {

return Binder<S>(base, scheduler: scheduler) { t, e in
t.asStore().commit { s in
t.store.asStore().commit { s in
mutate(&s, e)
}
}
Expand All @@ -320,7 +320,7 @@ extension Reactive where Base : StoreType {
) -> Binder<S?> {

return Binder<S?>(base, scheduler: scheduler) { t, e in
t.asStore().commit { s in
t.store.asStore().commit { s in
mutate(&s, e)
}
}
Expand All @@ -333,7 +333,7 @@ extension Reactive where Base : StoreType {
) -> Binder<S> {

return Binder<S>(base, scheduler: scheduler) { t, e in
t.asStore().commit { s in
t.store.asStore().commit { s in
s[keyPath: target] = e
}
}
Expand All @@ -346,7 +346,7 @@ extension Reactive where Base : StoreType {
) -> Binder<S?> {

return Binder<S?>(base, scheduler: scheduler) { t, e in
t.asStore().commit { s in
t.store.asStore().commit { s in
s[keyPath: target] = e
}
}
Expand Down

0 comments on commit 1f528bf

Please sign in to comment.