Switch to state management using reference types #1

Merged
david-swift merged 1 commits from reference-state-management into main 2024-08-31 15:20:04 +02:00
david-swift commented 2024-08-31 15:18:56 +02:00 (Migrated from github.com)

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.

## Steps - [x] Build the project on your machine. If it does not compile, fix the errors. - [x] Describe the purpose and approach of your pull request below. - [x] 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: ```swift 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.
Sign in to join this conversation.
No Reviewers
No Milestone
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: aparoksha/meta#1
No description provided.