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

Fix Observation notification not triggering on nested properties #8298

Merged
merged 2 commits into from
Jul 24, 2023

Conversation

dianaafanador3
Copy link
Contributor

@dianaafanador3 dianaafanador3 commented Jul 11, 2023

This fix will create false positive PropertyChanges for projection properties which have the same origin property root.

  - warning: For projected properties where the original property has the same root property name,
             this will trigger a `PropertyChange` for each of the Projected properties even though
             the change only corresponds to one of them.
             For the following `Projection` object
             ```swift
             class PersonProjection: Projection<Person> {
                 @Projected(\Person.firstName) var name
                 @Projected(\Person.address.country) originCountry
                 @Projected(\Person.address.phone.number) mobile
             }
             let token = projectedPerson.observe { changes in
                 if case .change(_, let propertyChanges) = changes {
                     propertyChanges[0].newValue as? String, "Winterfell" // Will notify the new value
                     propertyChanges[1].newValue as? String, "555-555-555" // Will notify with the current value, which hasn't change.
                 }
             })
             try realm.write {
                 person.address.country = "Winterfell"
             }
             ```

@cla-bot cla-bot bot added the cla: yes label Jul 11, 2023
@dianaafanador3 dianaafanador3 force-pushed the dp/fix_nested_projection_observation branch 3 times, most recently from 4fddfd4 to 942817b Compare July 14, 2023 09:38
@dianaafanador3 dianaafanador3 force-pushed the dp/fix_nested_projection_observation branch from 942817b to 7c3aadf Compare July 20, 2023 16:58
@dianaafanador3 dianaafanador3 marked this pull request as ready for review July 20, 2023 18:37
Test.xcworkspace/contents.xcworkspacedata Outdated Show resolved Hide resolved
RealmSwift/Projection.swift Outdated Show resolved Hide resolved
RealmSwift/Projection.swift Outdated Show resolved Hide resolved
@dianaafanador3 dianaafanador3 merged commit cd65607 into master Jul 24, 2023
1 check passed
@dianaafanador3 dianaafanador3 deleted the dp/fix_nested_projection_observation branch July 24, 2023 07:03
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants