johnpatrickmorgan / FlowStacks

FlowStacks allows you to hoist SwiftUI navigation and presentation state into a Coordinator
MIT License
854 stars 66 forks source link

flowDestination calling multiple times. #77

Closed phamdinhduc795397 closed 4 months ago

phamdinhduc795397 commented 4 months ago

Hello, I discovered an issue with flowDestination. When adding a value to FlowPath or Routes, flowDestination is called multiple times.

johnpatrickmorgan commented 4 months ago

Thanks for raising this. I think it will be necessary to add some caching to avoid calling the closure repeatedly. I will investigate that.

phamdinhduc795397 commented 4 months ago

Hi @johnpatrickmorgan, do you have any suggestions for caching?

DeanFs commented 4 months ago

Hi @johnpatrickmorgan do you have any suggestions for this issue? This issue has a serious impact on my project. I really hope to get your help. Thank you very much!

phamdinhduc795397 commented 4 months ago

@DeanFs If you're using MVVM, you can save ViewModel/ObservableObject on routes to avoid renewing instances when flowDestination is called multiple times.

johnpatrickmorgan commented 4 months ago

Hi @johnpatrickmorgan do you have any suggestions for this issue? This issue has a serious impact on my project. I really hope to get your help. Thank you very much!

Sorry @DeanFs, I'm still figuring out the best way to avoid calling the closure repeatedly. So I understand fully, in what way is it impacting your project please? Thanks

DeanFs commented 4 months ago

Sorry @DeanFs, I'm still figuring out the best way to avoid calling the closure repeatedly. So I understand fully, in what way is it impacting your project please? Thanks

Hi @johnpatrickmorgan It just caused some trouble with page initialization. For example, a statement that inserts a new instance in the CoreData context at initialization will result in the insertion of many more pieces of meaningless junk data. At present, the implementation method has been changed, and the problem has been solved. But I will continue to pay attention to this issue, once you have the best solution, please let me know! Thank you again for such an excellent framework!

johnpatrickmorgan commented 4 months ago

I've made a change to ensure the closure isn't called more than once for the same data at the same index, released in v0.6.4. Thanks for your patience!