pointfreeco / episode-code-samples

💾 Point-Free episode code.
https://www.pointfree.co
MIT License
973 stars 294 forks source link

[suggestion] Add scope to ViewState #62

Closed toddwbates closed 3 years ago

toddwbates commented 4 years ago

Adding the scope function allows views to deal exclusively with ViewState objects. This simplifies usage because Views are passed the object they actually use rather than having to transform the Store into a ViewStore. This also simplifies ownership.

I have also added utility methods to ViewStore for bindings that allow snapshot tests to report full coverage. For example in Counter.swift line 183

    Button("+") { self.viewStore.send(.incrTapped) } 

would not be reported as full coverage because of the closure while this is

    Button("+", action: self.viewStore.curry(.incrTapped)) 

The same with CounterView_macO line 57

.popover( isPresented: Binding( get: { self.viewStore.value.isPrimePopoverShown }, set: { _ in self.viewStore.send(.primePopoverDismissed) } )

becomes

.popover( isPresented:
  self.viewStore.bind(/.isPrimePopoverShown,\.primePopoverDismissed)
) {

I have a fork with the changes here,

https://github.com/toddwbates/episode-code-samples

toddwbates commented 4 years ago

I just saw episode 99 and you already have bindings. I suspect next week will cover the rest;-)

stephencelis commented 3 years ago

Thanks for starting the discussion, and sorry for not seeing till now! 😄 Going to move over to the discussions tab.