Skip to content

Commit 2678418

Browse files
committed
Clean up deprecation formatting (#1207)
* Clean up deprecation formatting Didn't realize multiline worked here, but should make it easier to read without word wrap * Update Sources/ComposableArchitecture/Internal/Deprecations.swift * Update Sources/ComposableArchitecture/Internal/Deprecations.swift
1 parent f583315 commit 2678418

File tree

1 file changed

+96
-68
lines changed

1 file changed

+96
-68
lines changed

Sources/ComposableArchitecture/Internal/Deprecations.swift

Lines changed: 96 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import SwiftUI
2020
/// - environment: The environment of dependencies for the application.
2121
@available(
2222
*, deprecated,
23-
message:
23+
message:
2424
"""
2525
If you use this initializer, please open a discussion on GitHub and let us know how: \
2626
https://github.com/pointfreeco/swift-composable-architecture/discussions/new
@@ -69,7 +69,10 @@ extension Effect {
6969
*,
7070
deprecated,
7171
message:
72-
"Using a variadic list is no longer supported. Use an array of identifiers instead. For more on this change, see: https://github.com/pointfreeco/swift-composable-architecture/pull/1041"
72+
"""
73+
Using a variadic list is no longer supported. Use an array of identifiers instead. For more \
74+
on this change, see: https://github.com/pointfreeco/swift-composable-architecture/pull/1041
75+
"""
7376
)
7477
@_disfavoredOverload
7578
public static func cancel(ids: AnyHashable...) -> Self {
@@ -369,7 +372,10 @@ extension Store {
369372
@available(
370373
*, deprecated,
371374
message:
372-
"If you use this method, please open a discussion on GitHub and let us know how: https://github.com/pointfreeco/swift-composable-architecture/discussions/new"
375+
"""
376+
If you use this method, please open a discussion on GitHub and let us know how: \
377+
https://github.com/pointfreeco/swift-composable-architecture/discussions/new
378+
"""
373379
)
374380
public func producerScope<LocalState, LocalAction>(
375381
state toLocalState: @escaping (Effect<State, Never>) -> Effect<LocalState, Never>,
@@ -412,7 +418,10 @@ extension Store {
412418
@available(
413419
*, deprecated,
414420
message:
415-
"If you use this method, please open a discussion on GitHub and let us know how: https://github.com/pointfreeco/swift-composable-architecture/discussions/new"
421+
"""
422+
If you use this method, please open a discussion on GitHub and let us know how: \
423+
https://github.com/pointfreeco/swift-composable-architecture/discussions/new
424+
"""
416425
)
417426
public func producerScope<LocalState>(
418427
state toLocalState: @escaping (Effect<State, Never>) -> Effect<LocalState, Never>
@@ -422,88 +431,107 @@ extension Store {
422431

423432
}
424433

425-
extension ViewStore where Action: BindableAction, Action.State == State {
426-
@available(
427-
*, deprecated,
428-
message:
429-
"Dynamic member lookup is no longer supported for bindable state. Instead of dot-chaining on the view store, e.g. 'viewStore.$value', invoke the 'binding' method on view store with a key path to the value, e.g. 'viewStore.binding(\\.$value)'. For more on this change, see: https://github.com/pointfreeco/swift-composable-architecture/pull/810"
434+
extension ViewStore where Action: BindableAction, Action.State == State {
435+
@available(
436+
*, deprecated,
437+
message:
438+
"""
439+
Dynamic member lookup is no longer supported for bindable state. Instead of dot-chaining on \
440+
the view store, e.g. 'viewStore.$value', invoke the 'binding' method on view store with a \
441+
key path to the value, e.g. 'viewStore.binding(\\.$value)'. For more on this change, see: \
442+
https://github.com/pointfreeco/swift-composable-architecture/pull/810
443+
"""
444+
)
445+
public subscript<Value: Equatable>(
446+
dynamicMember keyPath: WritableKeyPath<State, BindableState<Value>>
447+
) -> Binding<Value> {
448+
self.binding(
449+
get: { $0[keyPath: keyPath].wrappedValue },
450+
send: { .binding(.set(keyPath, $0)) }
430451
)
431-
public subscript<Value: Equatable>(
432-
dynamicMember keyPath: WritableKeyPath<State, BindableState<Value>>
433-
) -> Binding<Value> {
434-
self.binding(
435-
get: { $0[keyPath: keyPath].wrappedValue },
436-
send: { .binding(.set(keyPath, $0)) }
437-
)
438-
}
439452
}
453+
}
440454

441455
// NB: Deprecated after 0.25.0:
442456

443-
extension BindingAction {
444-
@available(
445-
*, deprecated,
446-
message:
447-
"For improved safety, bindable properties must now be wrapped explicitly in 'BindableState', and accessed via key paths to that 'BindableState', like '\\.$value'"
457+
extension BindingAction {
458+
@available(
459+
*, deprecated,
460+
message:
461+
"""
462+
For improved safety, bindable properties must now be wrapped explicitly in 'BindableState', \
463+
and accessed via key paths to that 'BindableState', like '\\.$value'
464+
"""
465+
)
466+
public static func set<Value: Equatable>(
467+
_ keyPath: WritableKeyPath<Root, Value>,
468+
_ value: Value
469+
) -> Self {
470+
.init(
471+
keyPath: keyPath,
472+
set: { $0[keyPath: keyPath] = value },
473+
value: value,
474+
valueIsEqualTo: { $0 as? Value == value }
448475
)
449-
public static func set<Value: Equatable>(
450-
_ keyPath: WritableKeyPath<Root, Value>,
451-
_ value: Value
452-
) -> Self {
453-
.init(
454-
keyPath: keyPath,
455-
set: { $0[keyPath: keyPath] = value },
456-
value: value,
457-
valueIsEqualTo: { $0 as? Value == value }
458-
)
459-
}
476+
}
460477

461-
@available(
462-
*, deprecated,
463-
message:
464-
"For improved safety, bindable properties must now be wrapped explicitly in 'BindableState', and accessed via key paths to that 'BindableState', like '\\.$value'"
465-
)
466-
public static func ~= <Value>(
467-
keyPath: WritableKeyPath<Root, Value>,
468-
bindingAction: Self
469-
) -> Bool {
470-
keyPath == bindingAction.keyPath
471-
}
478+
@available(
479+
*, deprecated,
480+
message:
481+
"""
482+
For improved safety, bindable properties must now be wrapped explicitly in 'BindableState', \
483+
and accessed via key paths to that 'BindableState', like '\\.$value'
484+
"""
485+
)
486+
public static func ~= <Value>(
487+
keyPath: WritableKeyPath<Root, Value>,
488+
bindingAction: Self
489+
) -> Bool {
490+
keyPath == bindingAction.keyPath
472491
}
492+
}
473493

474-
extension Reducer {
475-
@available(
476-
*, deprecated,
477-
message:
478-
"'Reducer.binding()' no longer takes an explicit extract function and instead the reducer's 'Action' type must conform to 'BindableAction'"
479-
)
494+
extension Reducer {
495+
@available(
496+
*, deprecated,
497+
message:
498+
"""
499+
'Reducer.binding()' no longer takes an explicit extract function and instead the reducer's \
500+
'Action' type must conform to 'BindableAction'
501+
"""
502+
)
480503
public func binding(action toBindingAction: @escaping (Action) -> BindingAction<State>?)
481504
-> Self
482505
{
483-
Self { state, action, environment in
484-
toBindingAction(action)?.set(&state)
485-
return self.run(&state, action, environment)
486-
}
506+
Self { state, action, environment in
507+
toBindingAction(action)?.set(&state)
508+
return self.run(&state, action, environment)
487509
}
488510
}
511+
}
489512

490513
#if canImport(SwiftUI)
491-
extension ViewStore {
492-
@available(
493-
*, deprecated,
494-
message:
495-
"For improved safety, bindable properties must now be wrapped explicitly in 'BindableState'. Bindings are now derived via 'ViewStore.binding' with a key path to that 'BindableState' (for example, 'viewStore.binding(\\.$value)'). For dynamic member lookup to be available, the view store's 'Action' type must also conform to 'BindableAction'."
514+
extension ViewStore {
515+
@available(
516+
*, deprecated,
517+
message:
518+
"""
519+
For improved safety, bindable properties must now be wrapped explicitly in 'BindableState'. \
520+
Bindings are now derived via 'ViewStore.binding' with a key path to that 'BindableState' \
521+
(for example, 'viewStore.binding(\\.$value)'). For dynamic member lookup to be available, \
522+
the view store's 'Action' type must also conform to 'BindableAction'.
523+
"""
524+
)
525+
public func binding<LocalState: Equatable>(
526+
keyPath: WritableKeyPath<State, LocalState>,
527+
send action: @escaping (BindingAction<State>) -> Action
528+
) -> Binding<LocalState> {
529+
self.binding(
530+
get: { $0[keyPath: keyPath] },
531+
send: { action(.set(keyPath, $0)) }
496532
)
497-
public func binding<LocalState: Equatable>(
498-
keyPath: WritableKeyPath<State, LocalState>,
499-
send action: @escaping (BindingAction<State>) -> Action
500-
) -> Binding<LocalState> {
501-
self.binding(
502-
get: { $0[keyPath: keyPath] },
503-
send: { action(.set(keyPath, $0)) }
504-
)
505-
}
506533
}
534+
}
507535
#endif
508536

509537
// NB: Deprecated after 0.23.0:

0 commit comments

Comments
 (0)