This repository was archived by the owner on Aug 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Draft
Conversation
# Conflicts: # Sources/StateKit/State/State.swift # Sources/StateKit/Store/ObservableViewStore.swift # Sources/StateKit/Store/StateSubscription.swift # Sources/StateKit/Store/Store.swift # Sources/StateKit/Store/ViewStore.swift # Sources/StateKit/UI/iOS/SwiftUI/UIKit Embedded/HostingController.swift # Sources/StateKit/UI/iOS/SwiftUI/UIKit Embedded/StateView.swift # Sources/StateKit/UI/iOS/SwiftUI/ViewWith.swift # Sources/StateKit/UI/iOS/UIKit/ViewController.swift
# Conflicts: # Sources/StateKit/Store/ObservableViewStore.swift # Sources/StateKit/Store/Store.swift # Sources/StateKit/UI/iOS/SwiftUI/UIKit Embedded/HostingController.swift # Sources/StateKit/UI/iOS/SwiftUI/ViewWith.swift # Sources/StateKit/UI/iOS/UIKit/ViewController.swift
# Conflicts: # Sources/StateKit/UI/iOS/SwiftUI/UIKit Embedded/HostingController.swift
# Conflicts: # Sources/StateKit/State/State.swift
# Conflicts: # Sources/StateKit/Store/ObservableViewStore.swift
@BergerBytes
BergerBytes
force-pushed
the
side-effects
branch
from
March 17, 2023 15:56
f37ca2c to
501d498
Compare
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Uh oh!
There was an error while loading. Please reload this page.
StateKit 0.4
Goals
StateKit 0.4 aims to support SideEffects. One of the more consistent, albeit infrequent, gaps in StateKit that comes up is allowing Stores to communicate non-persistent state. Common use cases are, toast messages, alerts, optional prompts and non-destructive outcomes from requests.
One of the core principles of StateKit is Stores deliver their state down a single path, in a single object. This allows principle is what gives StateKit its power and ease of use. Adding additional state outputs is a risk and requires great care. StateKit also tries to be as simple and straightforward as possible; adding SideEffects eases the pain of a few situations, but it can't be at the cost of adding additional complexity to StateKit in every situation.
Proposal
Introduce a new protocol type,
SideEffectSideEffects have no requirements and can be fulfilled by any type. Enums are the most likely option as they allow for exhaustive switching.Stores
Stores will require the
SideEffecttype definition.In an effort to keep
SideEffects from overcomplicating all stores that don't have need for them, there is an "opt-out" type that can be used,NoSideEffects; we will explore examples of this later.Example:
Nothing else changes within the store with this change, except that there is a new function to send effects to subscribers.
This is one of the things I least like about this approach. I have seen a lot of success with moving all the logic to the
Statestruct. TestingStateis very easy and they can be created mutated with transactions in a vacuum; if you ensure all queries and transactions are working as expected, there is very little in the store that needs to be tested. Moving a state emitter to the store separates this and could cause issues.Subscription
With the goal of keeping a single path for the state to flow, the subscriptions now return both a
StateContainerand an optionalSideEffectThis means
Stateis always provided with aSideEffect, an unneeded copy, but seen as a acceptable compromise over allowing optionalStateto have to be considered.