Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Concept] Accumulator #432

Merged
merged 18 commits into from
Jun 13, 2024
Merged

[Concept] Accumulator #432

merged 18 commits into from
Jun 13, 2024

Conversation

muukii
Copy link
Collaborator

@muukii muukii commented Oct 18, 2023

Compared to sink method, the Accumulator retains the selected value for itself not using Changes object.

sink method often drops the previous value due to receiving unordered events that happen by committing concurrently.
it's safe, but it's not happy for UI components that update themselves only when the value is updated.

Furthermore, the strategy of using the Changes structure may gain the cost of copying the state struct itself by growing state complexity. Verge might stop using this strategy. Each branch retaining the value from the root state should be affordable rather than that.

    let sub = store.accumulate { [weak self] in

     // here is escaping closure
      
      // subscribe count
      $0.ifChanged(\.count).do { value in
        // escaping closure but will be released after it runs.
        let _ = self
        exp.fulfill()
      }
      // subscribe name
      $0.ifChanged(\.name).do { value in
          // escaping closure but will be released after it runs.
        let _ = self

      }

    }
  • For MainQueue
  • For background queue

@muukii muukii requested a review from takumatt March 23, 2024 10:02
@muukii muukii marked this pull request as ready for review June 7, 2024 05:25
@muukii muukii merged commit 763855f into main Jun 13, 2024
1 check passed
@muukii muukii deleted the muukii/accumulation branch June 13, 2024 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant