You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Mini comes with a bare implementation and two external utility packages in order to ease the usage of the library named `MiniTasks` and `MiniPromises`, both dependant on the `Mini` base or core package.
47
+
46
48
```
47
49
$ swift build
48
50
```
@@ -53,6 +55,8 @@ $ swift build
53
55
54
56
```
55
57
pod "Mini-Swift"
58
+
# pod "Mini-Swift/MiniPromises"
59
+
# pod "Mini-Swift/MiniTasks"
56
60
```
57
61
58
62
- We also offer two subpecs for logging and testing:
@@ -77,42 +81,46 @@ pod "Mini-Swift/Test"
77
81
- For example:
78
82
79
83
```swift
80
-
structMyCoolState: State {
84
+
// If you're using MiniPromises
85
+
structMyCoolState: StateType {
81
86
let cool: Promise<Bool>
87
+
}
82
88
83
-
init(cool: Promise<Bool> = .idle()) {
84
-
self.cool= cool
85
-
}
86
-
87
-
// Conform to State protocol
88
-
funcisEqual(toother: State) ->Bool {
89
-
guardlet state = other as? MyCoolState else { returnfalse }
90
-
returnself.cool== state.cool
91
-
}
89
+
// If you're using MiniTasks
90
+
structMyCoolState: StateType {
91
+
let cool: Bool?
92
+
let coolTask: AnyTask
92
93
}
93
94
```
94
95
95
-
- The default inner state of a `Promise` is `idle`. It means that no `Action` (see more below), has started any operation over that `Promise`.
96
+
- The default inner state of a `Promise` is `idle`. On the other hand, the default inner state of a `Task` is `idle` as well. This means that no `Action` (see more below), has started any operation over that `Promise` or `Task`.
96
97
97
-
-A`Promise` can hold any kind of aditional properties that the developer might encounter useful for its implementation, for example, hold a `Date` for cache usage:
98
+
-Both`Promise` and `Task` can hold any kind of aditional properties that the developer might encounter useful for its implementation, for example, hold a `Date` for cache usage:
98
99
99
100
```swift
100
101
let promise: Promise<Bool> = .idle()
101
102
promise.date=Date()
102
103
// Later on...
103
104
let date: Date = promise.date
105
+
106
+
let task: AnyTask = .idle()
107
+
task.date=Date()
108
+
// Later on...
109
+
let date: Date = promise.date
104
110
```
105
111
106
112
- The core idea of a `State` is its [immutability](https://en.wikipedia.org/wiki/Immutable_object), so once created, no third-party objects are able to mutate it out of the control of the architecture flow.
107
113
108
-
- As can be seen in the example, a `State` has a pair of `Task` + `Result`*usually* (that can be any object, if any), which is related with the execution of the `Task`. In the example above, `CoolTask` is responsible, through its `Reducer` to fulfill the `Action` with the `Task` result and furthermore, the new `State`.
114
+
- As can be seen in the example, a `State` has a pair of `Task` + `Result`*usually* (that can be any object, if any), which is related with the execution of the `Task`. In the example above, `CoolTask` is responsible, through its `Reducer` to fulfill the `Action` with the `Task` result and furthermore, the new `State`.
115
+
116
+
- Furthermore, the `Promise` object unifies the _Status_ + _Result_ tuple, so it can store both the status of an ongoing task and the associated payload produced by it.
109
117
110
118
### Action
111
119
112
-
- An `Action` is the piece of information that is being dispatched through the architecture. Any `class` can conform to the `Action` protocol, with the only requirement of being unique its name per application.
120
+
- An `Action` is the piece of information that is being dispatched through the architecture. Any `struct` can conform to the `Action` protocol, with the only requirement of being unique its name per application.
113
121
114
122
```swift
115
-
classRequestContactsAccess: Action {
123
+
structRequestContactsAccess: Action {
116
124
// As simple as this is.
117
125
}
118
126
```
@@ -122,27 +130,17 @@ class RequestContactsAccess: Action {
122
130
- A `CompletableAction` is a specialization of the `Action` protocol, which allows the user attach both a `Task` and some kind of object that gets fulfilled when the `Task` succeeds.
- An `EmptyAction` is a specialization of `CompletableAction` where the `Payload` is a `Swift.Never`, this means it only has associated a `Promise<Never>`.
139
+
- An `EmptyAction` is a specialization of `CompletableAction` where the `Payload` is a `Swift.Void`, this means it only has associated a `Promise<Void>`.
137
140
138
141
```swift
139
142
classActivateVoucherLoaded: EmptyAction {
140
-
141
-
let activateVoucherPromise: Promise<Never>
142
-
143
-
requiredinit(promise: Promise<Never>) {
144
-
self.activateVoucherPromise= promise
145
-
}
143
+
let promise: Promise<Void>
146
144
}
147
145
```
148
146
- A `KeyedPayloadAction`, adds a `Key` (which is `Hashable`) to the `CompletableAction`. This is a special casewhere the same `Action` produces results that can be grouped together, tipically, under a `Dictionary` (i.e., an `Action` to search contacts, and grouped by their main phone number).
@@ -153,13 +151,12 @@ class RequestContactsAccess: Action {
153
151
typealiasPayload= CNContact
154
152
typealiasKey=String
155
153
156
-
let requestContactPromise: [Key: Promise<Payload?>]
157
-
158
-
requiredinit(promise: [Key: Promise<Payload?>]) {
159
-
self.requestContactPromise= promise
160
-
}
154
+
let promise: [Key: Promise<Payload?>]
161
155
}
162
156
```
157
+
158
+
> We take the advantage of using `struct`, so all initializers are automatically synthesized.
159
+
163
160
### Store
164
161
165
162
- A `Store` is the hub where decissions and side-efects are made through the ingoing and outgoing `Action`s. A `Store` is a generic classto inherit from and associate a `State` for it.
0 commit comments