Skip to content

Commit 3ec0217

Browse files
authored
Update README.md
1 parent b3d3210 commit 3ec0217

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

README.md

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ There is an Example app available [here](https://github.com/mdb1/ViewStateContro
88

99
# ViewStateController Object
1010

11-
The ViewStateController struct is the one that contains the array of historical [ViewStates](https://mdb1.github.io/2023-01-08-new-app-view-state/) and has computed properties that will be used by the ViewStateModifier to determine what to do.
11+
The [ViewStateController](https://github.com/mdb1/ViewStateController/blob/main/Sources/ViewStateController/ViewState/ViewStateController.swift) struct is the one that contains the array of historical [ViewStates](https://mdb1.github.io/2023-01-08-new-app-view-state/) and has computed properties that will be used by the ViewStateModifier to determine what to do.
1212

1313
* `isInitialLoading`: Returns true only if loading state was set once and there hasn't been errors or info yet.
1414
* `isLoading`: Returns true if state is loading.
@@ -23,35 +23,35 @@ There are also two mutating methods:
2323
* `setState(_ state: ViewState<Info>)`: Sets the new state into the states array.
2424
* `reset()`: Resets everything.
2525

26-
# ViewStateModifier
26+
## ViewStateModifier
2727

28-
The ViewStateModifier is a ViewModifier that uses the given ViewStateController and configurable options to automatically update the state of a view.
28+
The [ViewStateModifier](https://github.com/mdb1/ViewStateController/blob/main/Sources/ViewStateController/ViewModifiers/ViewStateModifier.swift) is a ViewModifier that uses the given ViewStateController and configurable options to automatically update the state of a view.
2929

3030
The code of the modifier is pretty straight forward:
3131
```swift
3232
func body(content: Content) -> some View {
33-
if controller.isInitialLoading {
34-
// Initial loading modifier displayed on the initial loading state.
35-
content.modifier(initialLoadingModifier)
36-
} else if let info = controller.latestValidInfo {
37-
// If we have valid info loaded we display it:
38-
loadedView(info)
39-
.if(controller.isLoading) { view in
40-
// If we are on a subsequent loading, we add the modifier.
41-
view.modifier(loadingAfterInfoModifier)
42-
}
43-
} else if let error = controller.latestValidError {
44-
// If we have a value error we display it:
45-
errorView(error)
46-
.if(controller.isLoading) { view in
47-
// If we are on a subsequent loading, we add the modifier.
48-
view.modifier(loadingAfterErrorModifier)
49-
}
50-
} else {
51-
// Otherwise, we display the initial content.
52-
content
53-
}
33+
if controller.isInitialLoading {
34+
// Initial loading modifier displayed on the initial loading state.
35+
content.modifier(initialLoadingModifier)
36+
} else if let info = controller.latestValidInfo {
37+
// If we have valid info loaded we display it:
38+
loadedView(info)
39+
.if(controller.isLoading) { view in
40+
// If we are on a subsequent loading, we add the modifier.
41+
view.modifier(loadingAfterInfoModifier)
42+
}
43+
} else if let error = controller.latestValidError {
44+
// If we have a value error we display it:
45+
errorView(error)
46+
.if(controller.isLoading) { view in
47+
// If we are on a subsequent loading, we add the modifier.
48+
view.modifier(loadingAfterErrorModifier)
49+
}
50+
} else {
51+
// Otherwise, we display the initial content.
52+
content
5453
}
54+
}
5555
```
5656

5757
The method `withViewStateModifier`, is just a convenience way to add the ViewStateModifier to any view:
@@ -79,6 +79,10 @@ func withViewStateModifier<Info, IndicatorView: View, LoadedView: View>(
7979
) -> some View
8080
```
8181

82+
## LoadingModifierType
83+
84+
The [LoadingModifierType](https://github.com/mdb1/ViewStateController/blob/main/Sources/ViewStateController/ViewModifiers/LoadingViewModifier.swift) provides some different loading options with configurable parameters.
85+
8286
## Usage
8387

8488
The ideal usage would be to:

0 commit comments

Comments
 (0)