-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEquals.swift
77 lines (61 loc) · 2.79 KB
/
Equals.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//=----------------------------------------------------------------------------=
// This source file is part of the DiffableTextViews open source project.
//
// Copyright (c) 2022 Oscar Byström Ericsson
// Licensed under Apache License, Version 2.0
//
// See http://www.apache.org/licenses/LICENSE-2.0 for license information.
//=----------------------------------------------------------------------------=
//*============================================================================*
// MARK: * Equals
//*============================================================================*
/// Binds the style's equality to a proxy.
///
/// Use this modifier to optimize the comparison on view update.
///
public struct EqualsTextStyle<Base, Equatable>: WrapperTextStyle
where Base: DiffableTextStyle, Equatable: Swift.Equatable {
public typealias Cache = Base.Cache
public typealias Value = Base.Value
//=------------------------------------------------------------------------=
// MARK: State
//=------------------------------------------------------------------------=
public var base: Base
public var equatable: Equatable
//=------------------------------------------------------------------------=
// MARK: Initializers
//=------------------------------------------------------------------------=
@inlinable public init(_ base: Base, equatable: Equatable) {
self.base = base; self.equatable = equatable
}
//=------------------------------------------------------------------------=
// MARK: Utilities
//=------------------------------------------------------------------------=
@inlinable public static func == (lhs: Self, rhs: Self) -> Bool {
lhs.equatable == rhs.equatable
}
}
//*============================================================================*
// MARK: * Equals x Style
//*============================================================================*
public extension DiffableTextStyle {
typealias Equals<T> = EqualsTextStyle<Self, T> where T: Equatable
typealias EqualsVoid = EqualsTextStyle<Self, _Void>
//=------------------------------------------------------------------------=
// MARK: Transformations
//=------------------------------------------------------------------------=
/// Binds the style's equality to a proxy.
///
/// Use this modifier to optimize the comparison on view update.
///
@inlinable func equals<T>(_ equatable: T) -> Equals<T> {
Equals(self, equatable: equatable)
}
/// Binds the style's equality to a proxy.
///
/// Use this modifier to optimize the comparison on view update.
///
@inlinable func equals(_ equatable: Void) -> EqualsVoid {
Equals(self, equatable: _Void())
}
}