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

Implement User/App listener #4522

Merged
merged 17 commits into from
May 4, 2022
Merged

Implement User/App listener #4522

merged 17 commits into from
May 4, 2022

Conversation

takameyer
Copy link
Contributor

@takameyer takameyer commented Apr 25, 2022

What, How & Why?

Add change listener for app and user

  • Add a member variable to store listener tokens to app and user.
  • Store the shared pointer to app and user as a member variable on User and App classes to ensure that the tokens are moved correctly and not copied.
    Write tests for app listener.

This closes #4455

☑️ ToDos

  • 📝 Changelog entry
  • 📝 Compatibility label is updated or copied from previous entry
  • 🚦 Tests
  • 📱 Check the React Native/other sample apps work if necessary
  • 📝 Public documentation PR created or is not necessary
  • 💥 Breaking label has been applied or is not necessary

If this PR adds or changes public API's:

  • typescript definitions file is updated
  • jsdoc files updated
  • Chrome debug API is updated if API is available on React Native

@cla-bot cla-bot bot added the cla: yes label Apr 25, 2022
@takameyer takameyer force-pushed the andrew/rr-user-listener branch 5 times, most recently from f0815d5 to 5f66dce Compare April 29, 2022 07:52
@takameyer takameyer marked this pull request as ready for review April 29, 2022 07:55
CHANGELOG.md Outdated Show resolved Hide resolved
docs/sync.js Show resolved Hide resolved
docs/sync.js Show resolved Hide resolved
docs/sync.js Outdated Show resolved Hide resolved
src/js_app.hpp Outdated Show resolved Hide resolved
src/js_sync.hpp Show resolved Hide resolved
src/js_user.hpp Outdated Show resolved Hide resolved
tests/js/app-tests.js Outdated Show resolved Hide resolved
tests/spec/unit_tests.js Outdated Show resolved Hide resolved
Copy link
Contributor

@tomduncalf tomduncalf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not completed review yet, just submitting a few comments

docs/sync.js Outdated Show resolved Hide resolved
docs/sync.js Outdated Show resolved Hide resolved
docs/sync.js Outdated Show resolved Hide resolved
using CallbackTokenPair = std::pair<Protected<typename T::Function>, AppToken>;
std::forward_list<CallbackTokenPair> m_notification_tokens;

SharedApp m_app;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you conclude that trying to extend shared_ptr directly was leading to issues?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having issues that went away by implementing it with a member. That being said, it's possible that it could work extending the shared_ptr directly. Maybe a second look would be worthwhile, but this time using ->get() to retrieve a reference to app instead of dereferencing directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That didn't work the way I had hoped. Found some reading on inheriting shared_ptr though..
https://stackoverflow.com/a/30309840/192046

src/js_app.hpp Outdated Show resolved Hide resolved
@kraenhansen
Copy link
Member

I just had a quick look so far. It looks like a couple of files were committed by accident:

  • tests/.lock
  • tests/realm-bundle.realm.backup-log

Now that we're adding to the Realm JS types, do you plan to extend Realm Web with this as well? Possibly in a follow up PR? Perhaps we need to revisit the scope to clarify that?

A heads up: Porting this to v11 will most likely involve the use of the NotificationBucket API that we introduced for all other things that are observable.

@takameyer
Copy link
Contributor Author

Now that we're adding to the Realm JS types, do you plan to extend Realm Web with this as well? Possibly in a follow up PR? Perhaps we need to revisit the scope to clarify that?

@kraenhansen I do not have realm-web on my radar, this was completely focused on @realm/react. We should plan time for that. I would need to familiarize myself with the project and its test framework. I think we should scope updates to realm-web in a separate agenda.

@takameyer
Copy link
Contributor Author

A heads up: Porting this to v11 will most likely involve the use of the NotificationBucket API that we introduced for all other things that are observable.

This should be applied to everything then (objects, collections, realm), and should be planned.

@takameyer takameyer force-pushed the andrew/rr-user-listener branch from 6462afa to ea7dc6f Compare April 29, 2022 09:52
@kraenhansen
Copy link
Member

This should be applied to everything then (objects, collections, realm), and should be planned.

It already has been implemented for the other observables.

@takameyer
Copy link
Contributor Author

It already has been implemented for the other observables.

Then I will have to make a second PR for the v11 branch.

src/js_app.hpp Outdated Show resolved Hide resolved
Copy link
Contributor

@tomduncalf tomduncalf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, just a few small comments

src/js_app.hpp Outdated Show resolved Hide resolved
src/js_app.hpp Outdated Show resolved Hide resolved
src/js_app.hpp Outdated Show resolved Hide resolved
src/js_app.hpp Outdated Show resolved Hide resolved
src/js_app.hpp Show resolved Hide resolved
src/js_app.hpp Show resolved Hide resolved
src/js_user.hpp Outdated Show resolved Hide resolved
@takameyer takameyer force-pushed the andrew/rr-user-listener branch from 77c40d7 to 89beeb2 Compare May 3, 2022 05:31
@kraenhansen kraenhansen mentioned this pull request May 3, 2022
6 tasks
src/js_app.hpp Show resolved Hide resolved
src/js_app.hpp Show resolved Hide resolved
src/js_app.hpp Show resolved Hide resolved
src/js_app.hpp Show resolved Hide resolved
src/js_app.hpp Show resolved Hide resolved
src/js_user.hpp Show resolved Hide resolved
src/js_user.hpp Show resolved Hide resolved
src/js_user.hpp Show resolved Hide resolved
src/js_user.hpp Show resolved Hide resolved
src/js_user.hpp Show resolved Hide resolved
takameyer added 5 commits May 3, 2022 13:26
Add a member variable to store listener tokens to app and user.
Store the shared pointer to app and user as a member variable on
User and App classes to ensure that the tokens are moved correctly
and not copied.
Write tests for app listener.
@kraenhansen kraenhansen force-pushed the andrew/rr-user-listener branch from 89beeb2 to 86c6320 Compare May 3, 2022 11:28
kraenhansen and others added 4 commits May 4, 2022 07:59
* Refactored NotificationBucket to take a Token type

* Using NotificationBucket for App and User
@takameyer takameyer force-pushed the andrew/rr-user-listener branch from 618b2e8 to 448de72 Compare May 4, 2022 10:47
@takameyer takameyer merged commit b4d6033 into master May 4, 2022
@takameyer takameyer deleted the andrew/rr-user-listener branch May 4, 2022 13:54
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 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.

Add a change listener for user events
5 participants