Introduce ModelFactoryProtocol#29
Closed
gordonbrander wants to merge 1 commit into
Closed
Conversation
Allows models to be created from a static `create` function, which returns an update (allowing intial fx to be scheduled). This also allows for full mocking of the environment for testing in cases where the model's initial state depends upon some syncronous property of the environment.
This was referenced Mar 29, 2023
gordonbrander
added a commit
that referenced
this pull request
Apr 3, 2023
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allows models to be created from a static
createfunction, which returns an update (allowing intial fx to be scheduled).This also allows for full mocking of the environment for testing in cases where the model's initial state depends upon some synchronous property of the environment.
Encountered the limitation above with current ObservableStore while working on subconsciousnetwork/subconscious#473. Some properties of the app model are initialized from UseDefaults. Ideally, these would be exposed on the environment to allow for mocking in tests.
Fixes #28