File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -57,6 +57,8 @@ internal extension BaseLoadableView {
5757 loaded ( cached)
5858 } else {
5959 switch vm. viewState {
60+ case . invalidated:
61+ EmptyView ( )
6062 case . notLoaded:
6163 notLoaded ( )
6264 case . loaded( let element) :
Original file line number Diff line number Diff line change @@ -81,6 +81,8 @@ public extension BaseLoadableViewModel {
8181 if !equal( oldItem, item) {
8282 viewState = . loaded( item)
8383 }
84+ case . invalidated:
85+ viewState = . loaded( item)
8486 }
8587 }
8688
@@ -93,6 +95,7 @@ public extension BaseLoadableViewModel {
9395 if !equal( oldItem, item) {
9496 viewState = . loaded( newItem)
9597 }
98+ case . invalidated: ( )
9699 }
97100 }
98101
Original file line number Diff line number Diff line change @@ -101,6 +101,9 @@ public extension IDedLoadableViewModel {
101101
102102 func refresh( showLoading: Bool ) async throws {
103103 do {
104+ guard !viewState. isInvalid else {
105+ return
106+ }
104107 guard let id = self . id else {
105108 throw LoadableViewError . noId
106109 }
@@ -129,6 +132,7 @@ public extension IDedLoadableViewModel {
129132 viewState = . loaded( item)
130133 }
131134 }
135+ case . invalidated: ( )
132136 }
133137 setIsLoading ( false )
134138 }
@@ -155,6 +159,10 @@ public extension IDedLoadableViewModel {
155159 return true
156160 }
157161
162+ func invalidate( ) {
163+ viewState = . invalidated
164+ }
165+
158166 func _refresh( ifID id: UUID , showLoading: Bool ) {
159167 guard self . id == id as? Self . ID else {
160168 return
Original file line number Diff line number Diff line change @@ -59,6 +59,8 @@ public extension LoadableViewModel {
5959 viewState = . loaded( item)
6060 }
6161 }
62+ case . invalidated:
63+ return
6264 }
6365 setIsLoading ( false )
6466 }
@@ -81,6 +83,10 @@ public extension LoadableViewModel {
8183 return true
8284 }
8385
86+ func invalidate( ) {
87+ viewState = . invalidated
88+ }
89+
8490 func _refresh( ifID id: UUID , showLoading: Bool ) {
8591 self . refresh ( showLoading: showLoading)
8692 }
Original file line number Diff line number Diff line change 44import Foundation
55
66public enum ViewState < T> {
7+ case invalidated
78 case notLoaded
89 case loaded( T )
910}
@@ -12,13 +13,20 @@ public extension ViewState {
1213 var loaded : T ? {
1314 switch self {
1415 case . loaded( let loaded) : return loaded
15- case . notLoaded: return nil
16+ case . notLoaded, . invalidated : return nil
1617 }
1718 }
1819
1920 var hasLoaded : Bool {
2021 loaded != nil
2122 }
23+
24+ var isInvalid : Bool {
25+ switch self {
26+ case . invalidated: return true
27+ case . loaded, . notLoaded: return false
28+ }
29+ }
2230}
2331
2432public enum Overlay {
You can’t perform that action at this time.
0 commit comments