Skip to content

Commit

Permalink
Update the documentation (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
DevYeom authored Sep 28, 2024
1 parent 559a24c commit f9b9211
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
14 changes: 8 additions & 6 deletions Sources/OneWay/PropertyWrappers/CopyOnWrite.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
// Copyright (c) 2022-2024 SeungYeop Yeom ( https://github.com/DevYeom ).
//

/// A property wrapper that allows for an easy way to eliminate the cost of copying large values
/// adopt copy-on-write behavior.
/// A property wrapper that facilitates the use of copy-on-write semantics to eliminate the cost of
/// copying large values.
///
/// When applied to a field, the corresponding value will always be heap-allocated. This happens
/// because this wrapper is a class and classes are always heap-allocated. Use of this wrapper is
/// required on large value types because they can overflow the Swift runtime stack.
/// When applied to a field, the corresponding value will always be heap-allocated because this
/// wrapper uses a class, and classes in Swift are always allocated on the heap. This is especially
/// useful for large value types, as it prevents stack overflow by ensuring the value is managed on
/// the heap instead of the stack. Additionally, the copy-on-write behavior helps avoid unnecessary
/// copying when the value is not modified, improving performance.
///
/// - SeeAlso: [Advice: Use copy-on-write semantics for large values](https://github.com/apple/swift/blob/main/docs/OptimizationTips.rst#advice-use-copy-on-write-semantics-for-large-values)
/// - SeeAlso: [Advice: Use copy-on-write semantics for large values](https://github.com/swiftlang/swift/blob/swift-6.0-RELEASE/docs/OptimizationTips.rst#advice-use-copy-on-write-semantics-for-large-values)
@propertyWrapper
public struct CopyOnWrite<Value> {
fileprivate final class Reference {
Expand Down
7 changes: 4 additions & 3 deletions Sources/OneWay/PropertyWrappers/Ignored.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

/// A property wrapper that acts like the same value, regardless of changes in its actual value.
///
/// When applied to a field and compared with an equals sign, it will always yield `true`. It is
/// useful when the actual value of the `State` changes, but rendering of the `View` is not
/// required.
/// When applied to a field and compared with an equals sign, it will always yield `true`. This
/// prevents the observers from recognizing the state as changed, even if the actual value has been
/// updated. It is particularly useful when you want to avoid triggering state changes, especially
/// in SwiftUI, where unnecessary re-renders of the `View` can be avoided.
@propertyWrapper
public struct Ignored<Value> {
public var wrappedValue: Value
Expand Down
5 changes: 3 additions & 2 deletions Sources/OneWay/PropertyWrappers/Triggered.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
/// the same value is assigned.
///
/// When applied to a field, assigning the same value will lead to different values for comparison.
/// It is useful in cases where the value hasn't actually changed, but the `View` needs to be
/// rendered again.
/// This ensures that observers will perceive the state as changed, even if the value itself remains
/// the same. It is particularly useful in SwiftUI, as it can trigger the `View` to re-render when
/// necessary, even if the value hasn't technically changed.
@propertyWrapper
public struct Triggered<Value> where Value: Equatable {
fileprivate struct Storage: Equatable {
Expand Down
2 changes: 1 addition & 1 deletion Sources/OneWay/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ where R.Action: Sendable, R.State: Sendable & Equatable {
}

/// The state stream that emits state when the state changes. Use this stream to observe the
/// state changes
/// state changes.
public var states: AsyncStream<State>

package var isIdle: Bool { !isProcessing && tasks.isEmpty }
Expand Down

0 comments on commit f9b9211

Please sign in to comment.