Commit 0d13440
authored
Allow initializing first update from closure (#30)
Introduce `init(create:environment:` convenience initializer.
Remove `init(update:action:environment:` convenience initializer.
This is an alternative to #29 for cases where we need to initialize store from an `Update`. Instead of introducing a `ModelFactoryProtocol`, we introduce a convenience initializer that takes a `create` closure.
An advantage here is that we do not have to create a `flags` type for customizing the model construction process. Instead, because we can choose which factory function is passed to `create`, we can create one-off closure factories that set the necessary properties on the model for a given view.
Additionally, this approach does not require us to specify the type signature of the Store, since Swift is able to infer the store type from the function's return type.
Fixes #28
Alternatives considered:
- #31
- #29.1 parent 2ae7450 commit 0d13440
2 files changed
Lines changed: 27 additions & 16 deletions
File tree
- Sources/ObservableStore
- Tests/ObservableStoreTests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
199 | | - | |
200 | | - | |
201 | | - | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
202 | 202 | | |
203 | | - | |
204 | | - | |
| 203 | + | |
205 | 204 | | |
206 | 205 | | |
207 | | - | |
208 | | - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
321 | | - | |
| 321 | + | |
322 | 322 | | |
323 | | - | |
324 | | - | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
325 | 328 | | |
326 | 329 | | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
| 330 | + | |
| 331 | + | |
331 | 332 | | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
332 | 344 | | |
333 | | - | |
| 345 | + | |
334 | 346 | | |
335 | 347 | | |
336 | 348 | | |
337 | | - | |
338 | 349 | | |
339 | 350 | | |
340 | 351 | | |
| |||
0 commit comments