-
Notifications
You must be signed in to change notification settings - Fork 0
/
TCA+.swift
46 lines (39 loc) · 955 Bytes
/
TCA+.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
//
// TCA+.swift
// Core
//
// Created by Young Bin on 2023/09/03.
// Copyright © 2023 team.humanwave. All rights reserved.
//
import ComposableArchitecture
private final class Ref<T: Equatable>: Equatable {
var val: T
init(_ v: T) {
self.val = v
}
static func == (lhs: Ref<T>, rhs: Ref<T>) -> Bool {
lhs.val == rhs.val
}
}
/// 스택 오버플로우 방지용 래퍼
/// 참고: https://github.com/pointfreeco/swift-composable-architecture/discussions/488
@propertyWrapper
public struct Box<T: Equatable>: Equatable {
private var ref: Ref<T>
public init(_ x: T) {
self.ref = Ref(x)
}
public var wrappedValue: T {
get { ref.val }
set {
if !isKnownUniquelyReferenced(&ref) {
ref = Ref(newValue)
return
}
ref.val = newValue
}
}
public var projectedValue: Box<T> {
self
}
}