Skip to content

Commit 8951581

Browse files
authored
Merge branch 'master' into auto-interrupt
2 parents 1e75a41 + d635059 commit 8951581

File tree

5 files changed

+73
-65
lines changed

5 files changed

+73
-65
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
1. If the input observer of a `Signal` deinitializes while the `Signal` has not yet terminated, an `interrupted` event would now be automatically sent. (#463, kudos to @andersio)
55

6+
1. `ValidationResult` and `ValidatorOutput` have been renamed to `ValidatingProperty.Result` and `ValidatingProperty.Decision`, respectively. (#443)
7+
68
1. Mitigated a race condition related to ARC in the `Signal` internal. (#456, kudos to @andersio)
79

810
1. Added new convenience initialisers to `Action` that make creating actions with state input properties easier. When creating an `Action` that is conditionally enabled based on an optional property, use the renamed `Action.init(unwrapping:execute:)` initialisers. (#455, kudos to @sharplet)

Documentation/FrameworkOverview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ Schedulers are also somewhat similar to `NSOperationQueue`, but schedulers
211211
do not allow tasks to be reordered or depend on one another.
212212

213213

214-
[Design Guidelines]: DesignGuidelines.md
214+
[Design Guidelines]: APIContracts.md
215215
[BasicOperators]: BasicOperators.md
216216
[README]: ../README.md
217217
[ReactiveCocoa]: https://github.com/ReactiveCocoa/

Sources/Deprecations+Removals.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ public protocol BindingTargetProtocol {}
167167
public protocol AtomicProtocol {}
168168

169169
// MARK: Deprecated types in ReactiveSwift 1.x.
170+
@available(*, unavailable, renamed:"ValidationProperty.Result")
171+
public typealias ValidationResult<Value, Error: Swift.Error> = ValidatingProperty<Value, Error>.Result
172+
173+
@available(*, unavailable, renamed:"ValidationProperty.Decision")
174+
public typealias ValidatorOutput<Value, Error: Swift.Error> = ValidatingProperty<Value, Error>.Decision
175+
170176
extension Signal where Value == Bool {
171177
@available(*, unavailable, renamed: "negate()")
172178
public var negated: Signal<Bool, Error> {

Sources/ValidatingProperty.swift

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public final class ValidatingProperty<Value, ValidationError: Swift.Error>: Muta
2323
private let setter: (Value) -> Void
2424

2525
/// The result of the last attempted edit of the root property.
26-
public let result: Property<ValidationResult<Value, ValidationError>>
26+
public let result: Property<Result>
2727

2828
/// The current value of the property.
2929
///
@@ -59,7 +59,7 @@ public final class ValidatingProperty<Value, ValidationError: Swift.Error>: Muta
5959
/// - validator: The closure to invoke for any proposed value to `self`.
6060
public init<Inner: ComposableMutablePropertyProtocol>(
6161
_ inner: Inner,
62-
_ validator: @escaping (Value) -> ValidatorOutput<Value, ValidationError>
62+
_ validator: @escaping (Value) -> Decision
6363
) where Inner.Value == Value {
6464
getter = { inner.value }
6565
producer = inner.producer
@@ -71,18 +71,18 @@ public final class ValidatingProperty<Value, ValidationError: Swift.Error>: Muta
7171
var isSettingInnerValue = false
7272

7373
(result, setter) = inner.withValue { initial in
74-
let mutableResult = MutableProperty(ValidationResult(initial, validator(initial)))
74+
let mutableResult = MutableProperty(Result(initial, validator(initial)))
7575

7676
mutableResult <~ inner.signal
7777
.filter { _ in !isSettingInnerValue }
78-
.map { ValidationResult($0, validator($0)) }
78+
.map { Result($0, validator($0)) }
7979

8080
return (Property(capturing: mutableResult), { input in
8181
// Acquire the lock of `inner` to ensure no modification happens until
8282
// the validation logic here completes.
8383
inner.withValue { _ in
8484
let writebackValue: Value? = mutableResult.modify { result in
85-
result = ValidationResult(input, validator(input))
85+
result = Result(input, validator(input))
8686
return result.value
8787
}
8888

@@ -108,7 +108,7 @@ public final class ValidatingProperty<Value, ValidationError: Swift.Error>: Muta
108108
/// - validator: The closure to invoke for any proposed value to `self`.
109109
public convenience init(
110110
_ initial: Value,
111-
_ validator: @escaping (Value) -> ValidatorOutput<Value, ValidationError>
111+
_ validator: @escaping (Value) -> Decision
112112
) {
113113
self.init(MutableProperty(initial), validator)
114114
}
@@ -128,7 +128,7 @@ public final class ValidatingProperty<Value, ValidationError: Swift.Error>: Muta
128128
public convenience init<Other: PropertyProtocol>(
129129
_ inner: MutableProperty<Value>,
130130
with other: Other,
131-
_ validator: @escaping (Value, Other.Value) -> ValidatorOutput<Value, ValidationError>
131+
_ validator: @escaping (Value, Other.Value) -> Decision
132132
) {
133133
// Capture a copy that reflects `other` without influencing the lifetime of
134134
// `other`.
@@ -173,7 +173,7 @@ public final class ValidatingProperty<Value, ValidationError: Swift.Error>: Muta
173173
public convenience init<Other: PropertyProtocol>(
174174
_ initial: Value,
175175
with other: Other,
176-
_ validator: @escaping (Value, Other.Value) -> ValidatorOutput<Value, ValidationError>
176+
_ validator: @escaping (Value, Other.Value) -> Decision
177177
) {
178178
self.init(MutableProperty(initial), with: other, validator)
179179
}
@@ -193,7 +193,7 @@ public final class ValidatingProperty<Value, ValidationError: Swift.Error>: Muta
193193
public convenience init<U, E>(
194194
_ inner: MutableProperty<Value>,
195195
with other: ValidatingProperty<U, E>,
196-
_ validator: @escaping (Value, U) -> ValidatorOutput<Value, ValidationError>
196+
_ validator: @escaping (Value, U) -> Decision
197197
) {
198198
self.init(inner, with: other, validator)
199199
}
@@ -212,7 +212,7 @@ public final class ValidatingProperty<Value, ValidationError: Swift.Error>: Muta
212212
public convenience init<U, E>(
213213
_ initial: Value,
214214
with other: ValidatingProperty<U, E>,
215-
_ validator: @escaping (Value, U) -> ValidatorOutput<Value, ValidationError>
215+
_ validator: @escaping (Value, U) -> Decision
216216
) {
217217
// Capture only `other.result` but not `other`.
218218
let otherValidations = other.result
@@ -254,74 +254,74 @@ public final class ValidatingProperty<Value, ValidationError: Swift.Error>: Muta
254254
}
255255
}
256256
}
257-
}
258257

259-
/// Represents a decision of a validator of a validating property made on a
260-
/// proposed value.
261-
public enum ValidatorOutput<Value, Error: Swift.Error> {
262-
/// The proposed value is valid.
263-
case valid
258+
/// Represents a decision of a validator of a validating property made on a
259+
/// proposed value.
260+
public enum Decision {
261+
/// The proposed value is valid.
262+
case valid
264263

265-
/// The proposed value is invalid, but the validator coerces it into a
266-
/// replacement which it deems valid.
267-
case coerced(Value, Error?)
264+
/// The proposed value is invalid, but the validator coerces it into a
265+
/// replacement which it deems valid.
266+
case coerced(Value, ValidationError?)
268267

269-
/// The proposed value is invalid.
270-
case invalid(Error)
271-
}
268+
/// The proposed value is invalid.
269+
case invalid(ValidationError)
270+
}
272271

273-
/// Represents the result of the validation performed by a validating property.
274-
public enum ValidationResult<Value, Error: Swift.Error> {
275-
/// The proposed value is valid.
276-
case valid(Value)
272+
/// Represents the result of the validation performed by a validating property.
273+
public enum Result {
274+
/// The proposed value is valid.
275+
case valid(Value)
277276

278-
/// The proposed value is invalid, but the validator was able to coerce it
279-
/// into a replacement which it deemed valid.
280-
case coerced(replacement: Value, proposed: Value, error: Error?)
277+
/// The proposed value is invalid, but the validator was able to coerce it
278+
/// into a replacement which it deemed valid.
279+
case coerced(replacement: Value, proposed: Value, error: ValidationError?)
281280

282-
/// The proposed value is invalid.
283-
case invalid(Value, Error)
281+
/// The proposed value is invalid.
282+
case invalid(Value, ValidationError)
284283

285-
/// Whether the value is invalid.
286-
public var isInvalid: Bool {
287-
if case .invalid = self {
288-
return true
289-
} else {
290-
return false
284+
/// Whether the value is invalid.
285+
public var isInvalid: Bool {
286+
if case .invalid = self {
287+
return true
288+
} else {
289+
return false
290+
}
291291
}
292-
}
293292

294-
/// Extract the valid value, or `nil` if the value is invalid.
295-
public var value: Value? {
296-
switch self {
297-
case let .valid(value):
298-
return value
299-
case let .coerced(value, _, _):
300-
return value
301-
case .invalid:
302-
return nil
293+
/// Extract the valid value, or `nil` if the value is invalid.
294+
public var value: Value? {
295+
switch self {
296+
case let .valid(value):
297+
return value
298+
case let .coerced(value, _, _):
299+
return value
300+
case .invalid:
301+
return nil
302+
}
303303
}
304-
}
305304

306-
/// Extract the error if the value is invalid.
307-
public var error: Error? {
308-
if case let .invalid(_, error) = self {
309-
return error
310-
} else {
311-
return nil
305+
/// Extract the error if the value is invalid.
306+
public var error: ValidationError? {
307+
if case let .invalid(_, error) = self {
308+
return error
309+
} else {
310+
return nil
311+
}
312312
}
313-
}
314313

315-
fileprivate init(_ value: Value, _ output: ValidatorOutput<Value, Error>) {
316-
switch output {
317-
case .valid:
318-
self = .valid(value)
314+
fileprivate init(_ value: Value, _ decision: Decision) {
315+
switch decision {
316+
case .valid:
317+
self = .valid(value)
319318

320-
case let .coerced(replacement, error):
321-
self = .coerced(replacement: replacement, proposed: value, error: error)
319+
case let .coerced(replacement, error):
320+
self = .coerced(replacement: replacement, proposed: value, error: error)
322321

323-
case let .invalid(error):
324-
self = .invalid(value, error)
322+
case let .invalid(error):
323+
self = .invalid(value, error)
324+
}
325325
}
326326
}
327327
}

Tests/ReactiveSwiftTests/ValidatingPropertySpec.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ private enum FlattenedResult<Value: Equatable>: Equatable {
265265
case valid(Value)
266266
case coerced(Value, Value, TestError?)
267267

268-
init(_ result: ValidationResult<Value, TestError>) {
268+
init(_ result: ValidatingProperty<Value, TestError>.Result) {
269269
switch result {
270270
case let .valid(value):
271271
self = .valid(value)

0 commit comments

Comments
 (0)