Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Switch to state management using reference types #1

Merged
merged 1 commit into from
Aug 31, 2024

Conversation

david-swift
Copy link
Member

Steps

  • Build the project on your machine. If it does not compile, fix the errors.
  • Describe the purpose and approach of your pull request below.
  • Submit the pull request. Thank you very much for your contribution!

Purpose

The identifier system using value types only may have a slightly better performance (the difference really seems to be insignificant though), but results in strange behavior in certain situations:

struct Test: View {

    @State private var property1 = false
    @State private var property2 = false

    var view: Body {
        Button("Toggle") {
            property1.toggle()
            property2.toggle() // Nothing happens as the IDs already changed
        }
    }

}

With the reference type approach, the reference to the value will work as long as it exists and not break with the next update.

Approach

Remove StateManager's function of storing state and store state in a decentralized way instead.

@david-swift david-swift merged commit 46f5c32 into main Aug 31, 2024
2 checks passed
@david-swift david-swift deleted the reference-state-management branch August 31, 2024 13:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant