Skip to content

Commit

Permalink
Update pipeline (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii authored Jan 31, 2023
1 parent 32dd8d4 commit 54a9ab1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Sources/Verge/Derived/Derived.swift
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ extension Derived where Value == Never {
let buffer = VergeConcurrency.RecursiveLockAtomic.init(initial)

return Derived<Edge<(Changes<S0>, Changes<S1>)>>(
get: .map(\.root),
get: .map(\.self),
set: { _ in },
initialUpstreamState: initial,
subscribeUpstreamState: { callback in
Expand Down Expand Up @@ -486,7 +486,7 @@ extension Derived where Value == Never {
let buffer = VergeConcurrency.RecursiveLockAtomic.init(initial)

return Derived<Edge<(Changes<S0>, Changes<S1>, Changes<S2>)>>(
get: .map(\.root),
get: .map(\.self),
set: { _ in },
initialUpstreamState: initial,
subscribeUpstreamState: { callback in
Expand Down
34 changes: 17 additions & 17 deletions Sources/Verge/Store/Pipeline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ public enum Pipelines {

public typealias Input = Changes<Source>

public let keyPath: KeyPath<Input, Output>
public let keyPath: KeyPath<Input.Value, Output>
public let additionalDropCondition: ((Input) -> Bool)?

public init(
keyPath: KeyPath<Input, Output>,
keyPath: KeyPath<Input.Value, Output>,
additionalDropCondition: ((Input) -> Bool)?
) {
self.keyPath = keyPath
Expand All @@ -82,16 +82,16 @@ public enum Pipelines {
// }

guard let previous = input.previous else {
return .new(input[keyPath: keyPath])
return .new(input.primitive[keyPath: keyPath])
}

guard
previous.primitive == input.primitive ||
previous[keyPath: keyPath] == input[keyPath: keyPath]
previous.primitive[keyPath: keyPath] == input.primitive[keyPath: keyPath]
else {

guard let additionalDropCondition = additionalDropCondition, additionalDropCondition(input) else {
return .new(input[keyPath: keyPath])
return .new(input.primitive[keyPath: keyPath])
}

return .noUpdates
Expand All @@ -102,7 +102,7 @@ public enum Pipelines {
}

public func yield(_ input: Input) -> Output {
input[keyPath: keyPath]
input.primitive[keyPath: keyPath]
}

public func drop(while predicate: @escaping (Input) -> Bool) -> Self {
Expand All @@ -125,12 +125,12 @@ public enum Pipelines {

// MARK: - Properties

public let intermediate: (Input) -> PipelineIntermediate<Intermediate>
public let intermediate: (Input.Value) -> PipelineIntermediate<Intermediate>
public let transform: (Intermediate) -> Output
public let additionalDropCondition: ((Input) -> Bool)?

public init(
@PipelineIntermediateBuilder intermediate: @escaping (Input) -> PipelineIntermediate<Intermediate>,
@PipelineIntermediateBuilder intermediate: @escaping (Input.Value) -> PipelineIntermediate<Intermediate>,
transform: @escaping (Intermediate) -> Output,
additionalDropCondition: ((Input) -> Bool)?
) {
Expand All @@ -149,8 +149,8 @@ public enum Pipelines {

guard previous.primitive == input.primitive else {

let previousIntermediate = intermediate(previous)
let newIntermediate = intermediate(input)
let previousIntermediate = intermediate(previous.primitive)
let newIntermediate = intermediate(input.primitive)

guard previousIntermediate == newIntermediate else {

Expand All @@ -177,7 +177,7 @@ public enum Pipelines {
}

public func yield(_ input: Input) -> Output {
transform(intermediate(input).value)
transform(intermediate(input.primitive).value)
}

public func drop(while predicate: @escaping (Input) -> Bool) -> Self {
Expand Down Expand Up @@ -247,7 +247,7 @@ extension PipelineType {

exactly same with ``PipelineType/select(_:)``
*/
public static func map<Input, Output>(_ keyPath: KeyPath<Changes<Input>, Output>) -> Self
public static func map<Input, Output>(_ keyPath: KeyPath<Input, Output>) -> Self
where Input: Equatable, Output: Equatable, Self == Pipelines.ChangesSelectPipeline<Input, Output> {
select(keyPath)
}
Expand All @@ -258,7 +258,7 @@ extension PipelineType {

exactly same with ``PipelineType/map(_:)-7xvom``
*/
public static func select<Input, Output>(_ keyPath: KeyPath<Changes<Input>, Output>) -> Self
public static func select<Input, Output>(_ keyPath: KeyPath<Input, Output>) -> Self
where Input: Equatable, Output: Equatable, Self == Pipelines.ChangesSelectPipeline<Input, Output> {
self.init(keyPath: keyPath, additionalDropCondition: nil)
}
Expand All @@ -282,7 +282,7 @@ extension PipelineType {

*/
public static func map<Input, Intermediate, Output>(
@PipelineIntermediateBuilder using intermediate: @escaping (Changes<Input>) -> PipelineIntermediate<Intermediate>,
@PipelineIntermediateBuilder using intermediate: @escaping (Input) -> PipelineIntermediate<Intermediate>,
transform: @escaping (Intermediate) -> Output
) -> Self where Input: Equatable, Output: Equatable, Self == Pipelines.ChangesMapPipeline<Input, Intermediate, Output> {

Expand All @@ -299,7 +299,7 @@ extension PipelineType {
Using Edge as intermediate, output value will be unwrapped value from the Edge.
*/
public static func map<Input, EdgeIntermediate>(
@PipelineIntermediateBuilder using intermediate: @escaping (Changes<Input>) -> PipelineIntermediate<Edge<EdgeIntermediate>>
@PipelineIntermediateBuilder using intermediate: @escaping (Input) -> PipelineIntermediate<Edge<EdgeIntermediate>>
) -> Self where Input: Equatable, Output: Equatable, Self == Pipelines.ChangesMapPipeline<Input, Edge<EdgeIntermediate>, EdgeIntermediate> {

self.init(
Expand All @@ -317,8 +317,8 @@ extension PipelineType {
Consider to use intermediate value with `using` parameter variant if `map` closure takes much higher cost.
*/
public static func map<Input, Output>(
_ transform: @escaping (Changes<Input>) -> Output
) -> Self where Input: Equatable, Output: Equatable, Self == Pipelines.ChangesMapPipeline<Input, Changes<Input>, Output> {
_ transform: @escaping (Input) -> Output
) -> Self where Input: Equatable, Output: Equatable, Self == Pipelines.ChangesMapPipeline<Input, Input, Output> {

self.init(
intermediate: { $0 },
Expand Down
4 changes: 2 additions & 2 deletions Sources/VergeORM/Derived+ORM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ extension StoreType {
),
queue: queue
)
.chain(.map(\.root))
.chain(.map(\.self))

_nonatomic_derivedObjectCache.set(underlyingDerived, entityID: entityID, keyPathToDatabase: keyPathToDatabase)
}
Expand Down Expand Up @@ -338,7 +338,7 @@ extension StoreType {
),
queue: queue
)
.chain(.map(\.root))
.chain(.map(\.self))

_nonatomic_nonnull_derivedObjectCache.set(underlyingDerived, entityID: entity.entityID, keyPathToDatabase: keyPathToDatabase)
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/VergeTests/DerivedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ final class DerivedTests: XCTestCase {

weak var weakBaseSlice = baseSlice

var slice: Derived<Int>! = baseSlice.chain(.map { $0.root }, queue: .passthrough)
var slice: Derived<Int>! = baseSlice.chain(.map { $0.self }, queue: .passthrough)

baseSlice = nil

Expand Down

0 comments on commit 54a9ab1

Please sign in to comment.