Added createRcMemo primitive#853
Conversation
🦋 Changeset detectedLatest commit: 0ebdd1a The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
createRcMemois similar tocreateLazyMemoexcept its lifetime is bounded by the existence of listeners. (the listeners are reference counted.)createRcMemowas called inside.