Added createRcMemo primitive#853
Conversation
🦋 Changeset detectedLatest commit: 2c87347 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
atk
left a comment
There was a problem hiding this comment.
There is no documentation in the README.md, and this also needs a changeset file (please run npx changeset and add a minor version). Lastly, add createRcMemo to package.json in the primitive.list array.
| /** | ||
| * Reference counted `createMemo`. The memo calculation will only run when there is at least one listener. | ||
| * | ||
| * Once the number of listeners drops to zero, the internal memo will be disposed after a microtask. |
There was a problem hiding this comment.
Please add that the prev argument to the memo will be based on the previous value after being without listeners and being re-initialized, even if intermediate computations would have led to a different value. Maybe consider providing an additional stale argument (or similar mechanism) to the handler.
| let existing2 = existing!; | ||
| onCleanup(() => { | ||
| existing2.refCount--; | ||
| if (existing2.refCount == 0) { |
There was a problem hiding this comment.
Please use type-safe comparisons unless you consciously want to match other types, e.g. in line 485.
|
@atk I believe I have address your requested changes. Maybe you can try the Regarding I've used that |
|
@atk changeset added. Apologies for before, I did not understand how the |
|
@clinuxrulz I'm going to merge this in but our 2.0 implementation wont have the changes. I'll try to port it with a new PR later this evening. |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughA new ChangescreateRcMemo Reference-Counted Primitive
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
createRcMemois similar tocreateLazyMemoexcept its lifetime is bounded by the existence of listeners. (the listeners are reference counted.)createRcMemowas called inside.Summary by CodeRabbit
New Features
createRcMemo- a reference-counted memo primitive that automatically manages computational resources by executing only when active listeners exist, and cleaning up when all listeners are removed.Documentation
createRcMemodocumentation with usage examples and behavior details.