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: earlier onBecome(Un)Observed disposer will not dispose later listener (fix #1537) #1833

Merged
merged 2 commits into from
Dec 12, 2018

Conversation

fi3ework
Copy link
Contributor

@fi3ework fi3ework commented Dec 6, 2018

Thanks for taking the effort to create a PR!

If you are creating an extensive PR, you might want to open an issue with your idea first, so that you don't put a lot of effort in an PR that wouldn't be accepted. Please prepend pull requests with WIP: if they are not yet finished
PR checklist:

  • Added unit tests
  • Updated changelog
  • Updated docs (either in the description of this PR as markdown, or as separate PR on the gh-pages branch. Please refer to this PR). For new functionality, at least API.md should be updated
  • Added typescript typings
  • Verified that there is no significant performance drop (npm run perf)

This PR is to fix #1537, in become-observed.ts, there is a shared object to store the onBecomeObserved and onBecomeUnobserved for each Atom instance by name. Each Set of the hook of an atom will be initialized only when onBecomeUnobserved or onBecomeUnobserved invoked. So I think there's no harm to the performance.

Looking forward to your opinion 😆

Special thanks to #1771

@mayorovp
Copy link
Contributor

mayorovp commented Dec 7, 2018

I see two problems on this code:

  1. atom names is not guaranteed to be unique;
  2. properties on static object atomsObservedListeners are never deleted, so this code is source of memory leaks.

@fi3ework
Copy link
Contributor Author

fi3ework commented Dec 7, 2018

@mayorovp Thanks for replying.

  1. I think globalState.mobxGuid is just a simple global variable, and only affect by getNextId. Could give me hint why it's not guaranteed.
  2. The properties could be deleted when its listeners are removed. This problem could be fixed.

@mayorovp
Copy link
Contributor

mayorovp commented Dec 7, 2018

User can give any name to atoms manually.

@mayorovp
Copy link
Contributor

mayorovp commented Dec 7, 2018

  1. Who calls orig now? Looks like original handler is forgotten

@fi3ework
Copy link
Contributor Author

fi3ework commented Dec 7, 2018

Oh.. It's a fatal mistake I did not realize. Thanks, I' ll try to resolve it.

@fi3ework
Copy link
Contributor Author

fi3ework commented Dec 7, 2018

This pr has been rewrote. Welcome review.

src/api/become-observed.ts Outdated Show resolved Hide resolved
@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 93.605% when pulling 25eb682 on fi3ework:fix-#1537 into d55c50a on mobxjs:master.

@coveralls
Copy link

coveralls commented Dec 8, 2018

Coverage Status

Coverage increased (+0.05%) to 93.623% when pulling 009a482 on fi3ework:fix-#1537 into d55c50a on mobxjs:master.

@fi3ework
Copy link
Contributor Author

fi3ework commented Dec 8, 2018

Thanks for reviewing. The pr has updated, there's still an as because I don't know how to infer ${hook}Listeners to be "onBecomeObservedListeners" | "onBecomeUnobservedListeners" gracefully so far 😅

@mweststrate
Copy link
Member

Thanks @fi3ework !

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.

onBecome(Un)Observed intercept hooks can remove each other
4 participants