Skip to content

Commit

Permalink
Update warning for uncached stores. (#2764)
Browse files Browse the repository at this point in the history
* Update warning for uncached stores.

* update warnings

* Update tests'

* Update Store+Observation.swift

* Update ScopeCacheTests.swift

---------

Co-authored-by: Stephen Celis <stephen@stephencelis.com>
  • Loading branch information
mbrandonw and stephencelis committed Feb 2, 2024
1 parent 1f5985a commit 412a896
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,7 @@
) -> some RandomAccessCollection<Store<ElementState, ElementAction>> {
#if DEBUG
if !self.canCacheChildren {
runtimeWarn(
"""
Scoping from uncached \(self) is not compatible with observation. Ensure that all \
parent store scoping operations take key paths and case key paths instead of transform \
functions, which have been deprecated.
"""
)
runtimeWarn(uncachedStoreWarning(self))
}
#endif
return _StoreCollection(self.scope(state: state, action: action))
Expand Down
28 changes: 21 additions & 7 deletions Sources/ComposableArchitecture/Observation/Store+Observation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,7 @@
) -> Store<ChildState, ChildAction>? {
#if DEBUG
if !self.canCacheChildren {
runtimeWarn(
"""
Scoping from uncached \(self) is not compatible with observation. Ensure that all \
parent store scoping operations take key paths and case key paths instead of transform \
functions, which have been deprecated.
"""
)
runtimeWarn(uncachedStoreWarning(self))
}
#endif
guard var childState = self.state[keyPath: state]
Expand Down Expand Up @@ -302,4 +296,24 @@
}
}
}

func uncachedStoreWarning<State, Action>(_ store: Store<State, Action>) -> String {
"""
Scoping from uncached \(store) is not compatible with observation.
This can happen for one of two reasons:
• A parent view scopes on a store using transform functions, which has been \
deprecated, instead of with key paths and case paths. Read the migration guide for 1.5 \
to update these scopes: https://pointfreeco.github.io/swift-composable-architecture/\
main/documentation/composablearchitecture/migratingto1.5
• A parent feature is using deprecated navigation APIs, such as 'IfLetStore', \
'SwitchStore', 'ForEachStore', or any navigation view modifiers taking stores instead of \
bindings. Read the migration guide for 1.7 to update those APIs: \
https://pointfreeco.github.io/swift-composable-architecture/main/documentation/\
composablearchitecture/migratingto1.7
"""
}

#endif
57 changes: 45 additions & 12 deletions Tests/ComposableArchitectureTests/ScopeCacheTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,21 @@
.send(.show)
} issueMatcher: {
$0.compactDescription == """
Scoping from uncached StoreOf<Feature> is not compatible with observation. Ensure that all \
parent store scoping operations take key paths and case key paths instead of transform \
functions, which have been deprecated.
"""
Scoping from uncached StoreOf<Feature> is not compatible with observation.
This can happen for one of two reasons:
• A parent view scopes on a store using transform functions, which has been \
deprecated, instead of with key paths and case paths. Read the migration guide for 1.5 \
to update these scopes: https://pointfreeco.github.io/swift-composable-architecture/\
main/documentation/composablearchitecture/migratingto1.5
• A parent feature is using deprecated navigation APIs, such as 'IfLetStore', \
'SwitchStore', 'ForEachStore', or any navigation view modifiers taking stores instead of \
bindings. Read the migration guide for 1.7 to update those APIs: \
https://pointfreeco.github.io/swift-composable-architecture/main/documentation/\
composablearchitecture/migratingto1.7
"""
}
store.send(.child(.dismiss))
#endif
Expand Down Expand Up @@ -68,10 +79,21 @@
_ = cancellable
} issueMatcher: {
$0.compactDescription == """
Scoping from uncached StoreOf<Feature> is not compatible with observation. Ensure that all \
parent store scoping operations take key paths and case key paths instead of transform \
functions, which have been deprecated.
"""
Scoping from uncached StoreOf<Feature> is not compatible with observation.
This can happen for one of two reasons:
• A parent view scopes on a store using transform functions, which has been \
deprecated, instead of with key paths and case paths. Read the migration guide for 1.5 \
to update these scopes: https://pointfreeco.github.io/swift-composable-architecture/\
main/documentation/composablearchitecture/migratingto1.5
• A parent feature is using deprecated navigation APIs, such as 'IfLetStore', \
'SwitchStore', 'ForEachStore', or any navigation view modifiers taking stores instead of \
bindings. Read the migration guide for 1.7 to update those APIs: \
https://pointfreeco.github.io/swift-composable-architecture/main/documentation/\
composablearchitecture/migratingto1.7
"""
}
#endif
}
Expand Down Expand Up @@ -104,10 +126,21 @@
)
} issueMatcher: {
$0.compactDescription == """
Scoping from uncached StoreOf<Feature> is not compatible with observation. Ensure that all \
parent store scoping operations take key paths and case key paths instead of transform \
functions, which have been deprecated.
"""
Scoping from uncached StoreOf<Feature> is not compatible with observation.
This can happen for one of two reasons:
• A parent view scopes on a store using transform functions, which has been \
deprecated, instead of with key paths and case paths. Read the migration guide for 1.5 \
to update these scopes: https://pointfreeco.github.io/swift-composable-architecture/\
main/documentation/composablearchitecture/migratingto1.5
• A parent feature is using deprecated navigation APIs, such as 'IfLetStore', \
'SwitchStore', 'ForEachStore', or any navigation view modifiers taking stores instead of \
bindings. Read the migration guide for 1.7 to update those APIs: \
https://pointfreeco.github.io/swift-composable-architecture/main/documentation/\
composablearchitecture/migratingto1.7
"""
}
#endif
}
Expand Down

0 comments on commit 412a896

Please sign in to comment.