@krzyzanowskim There's nothing wrong with a singleton or NotificationCenter except you may need actions scoped independently some day. I don't have an answer to careful view hierarchy setup. It depends on your style and what you're guarding against. I like lumping environment dependencies into a single or small number of EnvironmentObjects that are passed by parameter at very high levels of the UI. Then they can be treated as (for-example) window-level singletons with more scoped access.
@krzyzanowskim Yeah I see, for this you need to extract whatever onCreateNote is applied to into another View type to attach (and read) the EnvironmentValue from there.
This Y- or T-shaped hierarchy of components (text field and button + their parent(s)) absolutely requires manual orchestration.
I also believe that's good, because I don't see how one would want to (!) design a component hierarchy differently.
Or go full Redux/TCA, but then everythings always indirect.
@krzyzanowskim One possible bus could be a shared value stored as a State in a common ancestor view. If giving the button a binding to this value is painful because the button is too deep, then why not using the SwiftUI environment to pass a closure inspired from EnvironmentValues.dismiss, refresh, etc ?
@krzyzanowskim if you don’t want to use a singleton (which I wouldn’t want to do), there isn’t really a way of doing this that doesn’t involve setting something up in a common ancestor.
Add comment