Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii committed Nov 12, 2023
1 parent d84e15d commit c839457
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions Sources/Verge/Store/Accumulator.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@

public protocol Sink {
associatedtype Source
func receive(source: Source)
}

public struct AccumulationBuilder<Source>: ~Copyable {

public func ifChanged<U: Equatable>(_ selector: @escaping (Source) -> U) -> IfChangedSink<U> {
.init(selector: selector)
}

public final class IfChangedSink<Target: Equatable> {
public final class IfChangedSink<Target: Equatable>: Sink {

private let selector: (Source) -> Target

private var latestValue: Target?
private var handler: ((consuming Target) -> Void)?

init(selector: @escaping (Source) -> Target) {
public init(selector: @escaping (Source) -> Target) {
self.selector = selector
}

Expand All @@ -21,7 +26,7 @@ public struct AccumulationBuilder<Source>: ~Copyable {
return self
}

func receive(source: Source) {
public func receive(source: Source) {

let selected = selector(source)

Expand Down Expand Up @@ -55,20 +60,21 @@ extension DispatcherType {

}

public struct SinkGroup<Source> {
public struct SinkGroup<Source>: Sink {

private let _receive: (Source) -> Void

init(receive: @escaping (Source) -> Void) {
self._receive = receive
}

func receive(source: Source) {
public func receive(source: Source) {
self._receive(source)
}
}

@resultBuilder public struct SinkComponentBuilder<Source> {
@resultBuilder
public struct SinkComponentBuilder<Source> {

public static func buildBlock() -> SinkGroup<Source> {
return .init(receive: { _ in })
Expand Down

0 comments on commit c839457

Please sign in to comment.