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: remove dangling variable references on model destroy #165

Merged
merged 3 commits into from
Feb 1, 2021

Conversation

aaron-steinfeld
Copy link
Contributor

Description

This change fixes a bug where dangling references are left over when a subtree of a model tree is destroyed. A later update of the variable would previously have attempted to access a destroyed model when updated. To fix this, we create a new lifecycle event that fires before a model is destroyed, allowing any defunct references to be cleaned up.

Testing

Added more unit tests, and updated existing ones.

Checklist:

  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules

@aaron-steinfeld aaron-steinfeld requested a review from a team as a code owner January 30, 2021 21:50
@github-actions

This comment has been minimized.

@codecov
Copy link

codecov bot commented Jan 30, 2021

Codecov Report

Merging #165 (0ec175e) into main (a77a498) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #165   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           52        53    +1     
  Lines         1429      1445   +16     
  Branches       194       195    +1     
=========================================
+ Hits          1429      1445   +16     
Impacted Files Coverage Δ
src/model/events/before-model-destroyed-event.ts 100.00% <100.00%> (ø)
src/model/manager/model-manager.ts 100.00% <100.00%> (ø)
src/variable/manager/variable-manager.ts 100.00% <100.00%> (ø)
src/variable/reference/variable-reference.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a77a498...0ec175e. Read the comment docs.

@github-actions

This comment has been minimized.

jake-bassett
jake-bassett previously approved these changes Feb 1, 2021
@@ -87,6 +89,10 @@ export class VariableManager {
referenceMap.set(location.toString(), reference);
}

this.beforeModelDestroyedEvent
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to unsubscribe here because the observable gets completed with the take(1), correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct - this observable emits exactly once, right before the destruction. This does remind me though - the reference may no longer exist at that point, so let me ensure that case doesn't error out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a test case and handled this situation (it was logging but not erroring - now it cleans up the subscription in this case, so it never outlasts its potential utility).

@github-actions

This comment has been minimized.

@aaron-steinfeld aaron-steinfeld merged commit 8f0052b into main Feb 1, 2021
@aaron-steinfeld aaron-steinfeld deleted the fix-variable-ref-on-destroy branch February 1, 2021 20:10
@github-actions
Copy link

github-actions bot commented Feb 1, 2021

Unit Test Results

    1 files  ±0    49 suites  +1   16s ⏱️ ±0s
296 tests +5  296 ✔️ +5  0 💤 ±0  0 ❌ ±0 
297 runs  +5  297 ✔️ +5  0 💤 ±0  0 ❌ ±0 

Results for commit 8f0052b. ± Comparison against base commit a77a498.

@github-actions
Copy link

github-actions bot commented Feb 1, 2021

🎉 This PR is included in version 1.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants