pointfreeco / swift-composable-architecture

A library for building applications in a consistent and understandable way, with composition, testing, and ergonomics in mind.
https://www.pointfree.co/collections/composable-architecture
MIT License
11.91k stars 1.37k forks source link

Disfavor shared optional dynamic member lookup #3170

Closed stephencelis closed 3 weeks ago

stephencelis commented 1 month ago

This makes the default work as expected, avoiding the issue brought up in #3169.

Technically this breaks the following invocation:

if let wrapped = $shared.optional { /* ... */ }

And limits the warning to:

func share<T>(_: Shared<T>?) {}
share($shared.optional)

We consider this lookup to be a bug, though, which is already deprecated in 1.11.0.

Since we encourage folks to migrate by one minor version at a time, we should only merge this when we plan on releasing 1.12.0.

acosmicflamingo commented 4 weeks ago

What would be the proper way to do something like this in newer versions of TCA? I'm seeing the 'subscript(dynamicMember:)' is deprecated warning:

 guard let row = state.$presentedData[id: itemId] else { return .none }
stephencelis commented 3 weeks ago

@acosmicflamingo The warning should give a hint. Is it not helpful?

You can use Shared.init to explicitly unwrap an optional shared, just like Binding.init.