-
Notifications
You must be signed in to change notification settings - Fork 167
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
Handle change notifications originating from Core #909
Merged
Merged
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
880ec07
wip
nirinchev 44598b4
wip
nirinchev 249e9d9
wip
nirinchev d48664e
Add tests for unmanaged NotifyPropertyChanged
nirinchev 7c6b5e9
more wip :/
nirinchev 3153ecc
wip
nirinchev 8ed45f9
Get notifications working for other-thread-realms
nirinchev 9b8bc36
Add support for unsubscribing
nirinchev addc3f2
Add logic to call property changed for instances on the same thread
nirinchev c3e17e6
Fix tests
nirinchev 3334919
Fix a few outstanding issues
nirinchev d2793df
Fix android build
nirinchev 692aa9d
Don't use the obsolete ReadOnly field
nirinchev 9da9034
Move register_notify_realm_object_changed to Realm static ctor
nirinchev bdf0c5f
address comments
nirinchev eeaf3d7
move the getter to the .hpp
nirinchev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,10 +50,6 @@ namespace binding { | |
return -1; | ||
} | ||
|
||
inline void* get_managed_object_handle(void* info) { | ||
return static_cast<ObservedObjectDetails*>(info)->managed_object_handle; | ||
} | ||
|
||
inline CSharpBindingContext* get_or_set_managed_context(SharedRealm& realm, void* managed_realm_handle) | ||
{ | ||
if (realm->m_binding_context == nullptr) { | ||
|
@@ -65,7 +61,7 @@ namespace binding { | |
|
||
CSharpBindingContext::CSharpBindingContext(void* managed_realm_handle) : m_managed_realm_handle(managed_realm_handle) | ||
{ | ||
observed_rows = std::vector<ObserverState>(); | ||
m_observed_rows = std::vector<ObserverState>(); | ||
} | ||
|
||
void CSharpBindingContext::did_change(std::vector<CSharpBindingContext::ObserverState> const& observed, std::vector<void*> const& invalidated) | ||
|
@@ -88,7 +84,7 @@ namespace binding { | |
|
||
std::vector<CSharpBindingContext::ObserverState> CSharpBindingContext::get_observed_rows() | ||
{ | ||
return observed_rows; | ||
return m_observed_rows; | ||
} | ||
|
||
void CSharpBindingContext::add_observed_row(const Object& object, void* managed_object_handle) | ||
|
@@ -97,42 +93,31 @@ namespace binding { | |
observer_state.row_ndx = object.row().get_index(); | ||
observer_state.table_ndx = object.row().get_table()->get_index_in_group(); | ||
observer_state.info = new ObservedObjectDetails(object.get_object_schema(), managed_object_handle); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this needs to be |
||
observed_rows.push_back(observer_state); | ||
m_observed_rows.push_back(std::move(observer_state)); | ||
} | ||
|
||
void CSharpBindingContext::remove_observed_row(void* managed_object_handle) | ||
{ | ||
if (!observed_rows.empty()) { | ||
for (auto it = observed_rows.begin(); it != observed_rows.end();) { | ||
if (get_managed_object_handle(it->info) == managed_object_handle) { | ||
it = observed_rows.erase(it); | ||
} else { | ||
++it; | ||
} | ||
} | ||
} | ||
} | ||
|
||
void* CSharpBindingContext::get_managed_realm_handle() | ||
{ | ||
return m_managed_realm_handle; | ||
remove_observed_rows([&](auto const* observer, auto const* details) { | ||
return details->managed_object_handle == managed_object_handle; | ||
}); | ||
} | ||
|
||
void CSharpBindingContext::notify_change(const size_t row_ndx, const size_t table_ndx, const size_t property_index) | ||
{ | ||
for (auto const& o : observed_rows) { | ||
for (auto const& o : m_observed_rows) { | ||
if (o.row_ndx == row_ndx && o.table_ndx == table_ndx) { | ||
notify_realm_object_changed(get_managed_object_handle(o.info), property_index); | ||
auto const& details = static_cast<ObservedObjectDetails*>(o.info); | ||
notify_realm_object_changed(details->managed_object_handle, property_index); | ||
} | ||
} | ||
} | ||
|
||
void CSharpBindingContext::notify_removed(const size_t row_ndx, const size_t table_ndx) | ||
{ | ||
if (!observed_rows.empty()) { | ||
observed_rows.erase(std::remove_if(observed_rows.begin(), observed_rows.end(), | ||
[&](auto const& row) { return row.row_ndx == row_ndx && row.table_ndx == table_ndx; })); | ||
} | ||
remove_observed_rows([&](auto const* observer, auto const* details) { | ||
return observer->row_ndx == row_ndx && observer->table_ndx == table_ndx; | ||
}); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to initialize this - the compiler will have added the necessary code to invoke the
std::vector
constructor in theCSharpBindingContext
constructor.