Model factory start#31
Closed
gordonbrander wants to merge 1 commit into
Closed
Conversation
This was referenced Mar 31, 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.
This PR illustrates a conceived-of solution to #28. The notion is to implement a
ModelFactoryProtocolthat implements astatic start(state: Self, environment: Self.Environment) -> Update<Self>. Essentially an opportunity to "decorate" a model and produce effects.However, the approach may not be ideal because models that initialize properties from environment still be required to have initial values for initializing BEFORE passing to
start. Its really not too different from theinit(state:action:environment:)convenience initializer in this way.