Skip to content

Commit bc687d5

Browse files
authored
Change property wrappers to intuitive names (#82)
1 parent 71fb483 commit bc687d5

File tree

6 files changed

+55
-49
lines changed

6 files changed

+55
-49
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,11 @@ for await number in store.states.number {
148148
// Prints "10", "20"
149149
```
150150

151-
If you want to continue receiving the value even when the same value is assigned to the `State`, you can use `@Sensitive`. For explanations of other useful property wrappers(e.g. [@CopyOnWrite](https://swiftpackageindex.com/devyeom/oneway/main/documentation/oneway/copyonwrite), [@Insensitive](https://swiftpackageindex.com/devyeom/oneway/main/documentation/oneway/insensitive)), refer to [here](https://swiftpackageindex.com/devyeom/oneway/main/documentation/oneway/sensitive).
151+
If you want to continue receiving the value even when the same value is assigned to the `State`, you can use `@Triggered`. For explanations of other useful property wrappers(e.g. [@CopyOnWrite](https://swiftpackageindex.com/devyeom/oneway/main/documentation/oneway/copyonwrite), [@Ignored](https://swiftpackageindex.com/devyeom/oneway/main/documentation/oneway/ignored)), refer to [here](https://swiftpackageindex.com/devyeom/oneway/main/documentation/oneway/triggered).
152152

153153
```swift
154154
struct State: Sendable, Equatable {
155-
@Sensitive var number: Int
155+
@Triggered var number: Int
156156
}
157157

158158
// number <- 10, 10, 20 ,20

Sources/OneWay/OneWay.docc/OneWay.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ OneWay is released under the MIT license. See LICENSE for details.
7878
### PropertyWrappers
7979

8080
- ``CopyOnWrite``
81-
- ``Insensitive``
82-
- ``Sensitive``
81+
- ``Ignored``
82+
- ``Triggered``
8383

8484
### Articles

Sources/OneWay/PropertyWrappers/Insensitive.swift renamed to Sources/OneWay/PropertyWrappers/Ignored.swift

+9-6
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,31 @@
1111
/// useful when the actual value of the `State` changes, but rendering of the `View` is not
1212
/// required.
1313
@propertyWrapper
14-
public struct Insensitive<Value> {
14+
public struct Ignored<Value> {
1515
public var wrappedValue: Value
1616

1717
public init(wrappedValue: Value) {
1818
self.wrappedValue = wrappedValue
1919
}
2020
}
2121

22-
extension Insensitive: CustomStringConvertible {
22+
extension Ignored: CustomStringConvertible {
2323
public var description: String {
2424
String(describing: wrappedValue)
2525
}
2626
}
2727

28-
extension Insensitive: Sendable where Value: Sendable { }
29-
extension Insensitive: Equatable {
30-
public static func == (lhs: Insensitive, rhs: Insensitive) -> Bool {
28+
extension Ignored: Sendable where Value: Sendable { }
29+
extension Ignored: Equatable {
30+
public static func == (lhs: Ignored, rhs: Ignored) -> Bool {
3131
true
3232
}
3333
}
34-
extension Insensitive: Hashable where Value: Hashable {
34+
extension Ignored: Hashable where Value: Hashable {
3535
public func hash(into hasher: inout Hasher) {
3636
hasher.combine(wrappedValue)
3737
}
3838
}
39+
40+
@available(*, deprecated, renamed: "Ignored")
41+
public typealias Insensitive = Ignored

Sources/OneWay/PropertyWrappers/Sensitive.swift renamed to Sources/OneWay/PropertyWrappers/Triggered.swift

+10-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/// It is useful in cases where the value hasn't actually changed, but the `View` needs to be
1313
/// rendered again.
1414
@propertyWrapper
15-
public struct Sensitive<Value> where Value: Equatable {
15+
public struct Triggered<Value> where Value: Equatable {
1616
fileprivate struct Storage: Equatable {
1717
var value: Value
1818
var version: UInt8
@@ -44,24 +44,27 @@ public struct Sensitive<Value> where Value: Equatable {
4444
}
4545
}
4646

47-
extension Sensitive: CustomStringConvertible {
47+
extension Triggered: CustomStringConvertible {
4848
public var description: String {
4949
String(describing: storage.value)
5050
}
5151
}
5252

53-
extension Sensitive: Sendable where Value: Sendable { }
54-
extension Sensitive: Equatable { }
55-
extension Sensitive: Hashable where Value: Hashable {
53+
extension Triggered: Sendable where Value: Sendable { }
54+
extension Triggered: Equatable { }
55+
extension Triggered: Hashable where Value: Hashable {
5656
public func hash(into hasher: inout Hasher) {
5757
hasher.combine(storage)
5858
}
5959
}
6060

61-
extension Sensitive.Storage: Sendable where Value: Sendable { }
62-
extension Sensitive.Storage: Hashable where Value: Hashable {
61+
extension Triggered.Storage: Sendable where Value: Sendable { }
62+
extension Triggered.Storage: Hashable where Value: Hashable {
6363
fileprivate func hash(into hasher: inout Hasher) {
6464
hasher.combine(value)
6565
hasher.combine(version)
6666
}
6767
}
68+
69+
@available(*, deprecated, renamed: "Triggered")
70+
public typealias Sensitive = Triggered

Tests/OneWayTests/PropertyWrappersTests.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ final class PropertyWrappersTests: XCTestCase {
5252
}
5353
}
5454

55-
func test_sensitive() {
55+
func test_triggered() {
5656
struct Storage: Equatable {
57-
@Sensitive var value: Int
57+
@Triggered var value: Int
5858
}
5959

6060
do {
@@ -83,9 +83,9 @@ final class PropertyWrappersTests: XCTestCase {
8383
}
8484
}
8585

86-
func test_insensitive() {
86+
func test_ignored() {
8787
struct Storage: Equatable {
88-
@Insensitive var value: Int
88+
@Ignored var value: Int
8989
}
9090

9191
do {

Tests/OneWayTests/ViewStoreTests.swift

+28-28
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ final class ViewStoreTests: XCTestCase {
4545
await sendableExpect { await sut.state.count == 4 }
4646
}
4747

48-
func test_sensitiveState() async {
48+
func test_triggeredState() async {
4949
actor Result {
5050
var counts: [Int] = []
51-
var sensitiveCounts: [Int] = []
51+
var triggeredCounts: [Int] = []
5252
func appendCount(_ count: Int) {
5353
counts.append(count)
5454
}
55-
func appendSensitiveCount(_ count: Int) {
56-
sensitiveCounts.append(count)
55+
func appendTriggeredCount(_ count: Int) {
56+
triggeredCounts.append(count)
5757
}
5858
}
5959
let result = Result()
@@ -64,28 +64,28 @@ final class ViewStoreTests: XCTestCase {
6464
}
6565
}
6666
Task { @MainActor in
67-
for await sensitiveCount in sut.states.sensitiveCount {
68-
await result.appendSensitiveCount(sensitiveCount)
67+
for await triggeredCount in sut.states.triggeredCount {
68+
await result.appendTriggeredCount(triggeredCount)
6969
}
7070
}
7171

72-
sut.send(.setSensitiveCount(10))
73-
sut.send(.setSensitiveCount(10))
74-
sut.send(.setSensitiveCount(10))
72+
sut.send(.setTriggeredCount(10))
73+
sut.send(.setTriggeredCount(10))
74+
sut.send(.setTriggeredCount(10))
7575

7676
await sendableExpect { await result.counts == [0, 0, 0, 0] }
77-
await sendableExpect { await result.sensitiveCounts == [0, 10, 10, 10] }
77+
await sendableExpect { await result.triggeredCounts == [0, 10, 10, 10] }
7878
}
7979

80-
func test_insensitiveState() async {
80+
func test_ignoredState() async {
8181
actor Result {
8282
var counts: [Int] = []
83-
var insensitiveCounts: [Int] = []
83+
var ignoredCounts: [Int] = []
8484
func appendCount(_ count: Int) {
8585
counts.append(count)
8686
}
87-
func appendInsensitiveCount(_ count: Int) {
88-
insensitiveCounts.append(count)
87+
func appendIgnoredCount(_ count: Int) {
88+
ignoredCounts.append(count)
8989
}
9090
}
9191
let result = Result()
@@ -96,18 +96,18 @@ final class ViewStoreTests: XCTestCase {
9696
}
9797
}
9898
Task { @MainActor in
99-
for await insensitiveCount in sut.states.insensitiveCount {
100-
await result.appendInsensitiveCount(insensitiveCount)
99+
for await ignoredCount in sut.states.ignoredCount {
100+
await result.appendIgnoredCount(ignoredCount)
101101
}
102102
}
103103

104-
sut.send(.setInsensitiveCount(10))
105-
sut.send(.setInsensitiveCount(20))
106-
sut.send(.setInsensitiveCount(30))
104+
sut.send(.setIgnoredCount(10))
105+
sut.send(.setIgnoredCount(20))
106+
sut.send(.setIgnoredCount(30))
107107

108108
// only initial value
109109
await sendableExpect { await result.counts == [0] }
110-
await sendableExpect { await result.insensitiveCounts == [0] }
110+
await sendableExpect { await result.ignoredCounts == [0] }
111111
}
112112

113113
func test_asyncViewStateSequence() async {
@@ -179,14 +179,14 @@ private struct TestReducer: Reducer {
179179
case twice
180180
case concat
181181
case setCount(Int)
182-
case setSensitiveCount(Int)
183-
case setInsensitiveCount(Int)
182+
case setTriggeredCount(Int)
183+
case setIgnoredCount(Int)
184184
}
185185

186186
struct State: Equatable {
187187
var count: Int
188-
@Sensitive var sensitiveCount: Int = 0
189-
@Insensitive var insensitiveCount: Int = 0
188+
@Triggered var triggeredCount: Int = 0
189+
@Ignored var ignoredCount: Int = 0
190190
}
191191

192192
func reduce(state: inout State, action: Action) -> AnyEffect<Action> {
@@ -213,12 +213,12 @@ private struct TestReducer: Reducer {
213213
state.count = count
214214
return .none
215215

216-
case .setSensitiveCount(let count):
217-
state.sensitiveCount = count
216+
case .setTriggeredCount(let count):
217+
state.triggeredCount = count
218218
return .none
219219

220-
case .setInsensitiveCount(let count):
221-
state.insensitiveCount = count
220+
case .setIgnoredCount(let count):
221+
state.ignoredCount = count
222222
return .none
223223
}
224224
}

0 commit comments

Comments
 (0)