-
-
Notifications
You must be signed in to change notification settings - Fork 5
feat: add computed peek #66
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
Conversation
🦋 Changeset detectedLatest commit: 72b889f The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 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 |
WalkthroughThe Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant unComputed
participant InternalState
User->>unComputed: Create with callback
User->>unComputed: .get()
unComputed->>InternalState: Retrieve value (reactive)
User->>unComputed: .peek()
unComputed->>InternalState: Retrieve value (non-reactive)
Possibly related PRs
Suggested labels
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caution
Changes requested ❌
Reviewed everything up to 44e5ba7 in 1 minute and 18 seconds. Click for details.
- Reviewed
153
lines of code in2
files - Skipped
0
files when reviewing. - Skipped posting
4
draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. packages/unuse-reactivity/src/unComputed/index.ts:67
- Draft comment:
Typographical error: it appears 'satisfies' is used where 'as' was intended, e.g. '16 satisfies ReactiveFlags.Dirty' should likely be '16 as ReactiveFlags.Dirty'. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% The 'satisfies' operator in TypeScript serves a different purpose than 'as' - it validates the type without widening it. In this case, it's being used to ensure the numeric literals match the ReactiveFlags enum values. The usage seems intentional and correct for type safety. The comment appears to misunderstand the purpose of 'satisfies' here. Could there be a performance impact from using 'satisfies' instead of 'as'? Could this be a pattern specific to this codebase that I'm not aware of? 'satisfies' is erased at runtime so there's no performance impact, and the consistent usage across the file suggests this is an intentional pattern for type safety with bit flags. The comment should be deleted as it suggests changing correct TypeScript usage that provides better type safety.
2. packages/unuse-reactivity/src/unComputed/index.ts:68
- Draft comment:
Typographical error: 'satisfies' is used instead of 'as' in 'flags & (32 satisfies ReactiveFlags.Pending)'. Please verify and correct if needed. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% The 'satisfies' operator is actually more type-safe than 'as' because it verifies the value matches the type without changing the inferred type. This appears to be intentional usage for type-checking numeric constants. The same pattern is used consistently in multiple places in the file. The comment is suggesting a change that would make the code less type-safe. Could there be a specific reason why 'as' would be preferred here? Maybe there's a performance implication I'm not considering? No, in this case type safety is more important than any minor performance differences, and 'satisfies' is the more appropriate operator for type-checking literal values against an enum. The comment should be deleted as it suggests changing intentional and correct usage of the 'satisfies' operator to a less type-safe alternative.
3. packages/unuse-reactivity/src/unComputed/index.ts:77
- Draft comment:
Typographical error: 'satisfies' is used where 'as' might have been intended in 'flags & (32 satisfies ReactiveFlags.Pending)'. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% The 'satisfies' operator in TypeScript is used to validate that a value matches a type without changing the type inference, while 'as' is a type assertion that can override TypeScript's type inference. In this case, 'satisfies' is actually a good choice as it provides type checking without changing the numeric literal type. The comment is suggesting a change that would make the code less type-safe. Could there be a performance or compatibility reason to prefer 'as' over 'satisfies'? Maybe there's a TypeScript version constraint I'm not considering? Even if there were version constraints, the code is already using 'satisfies' successfully, and it's the more type-safe choice for this use case. The comment is suggesting a less optimal solution. The comment should be deleted as it's suggesting a change that would make the code less type-safe, and the current usage of 'satisfies' is correct and intentional.
4. packages/unuse-reactivity/src/unComputed/index.ts:78
- Draft comment:
Typographical error: 'satisfies' is used in 'state.flags = flags & ~(32 satisfies ReactiveFlags.Pending)'; consider replacing it with 'as' to maintain consistency. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% The comment is incorrect. The use of 'satisfies' is actually consistent throughout the file for ReactiveFlags assertions. The one place where 'as' is used (line 58) is different because it's asserting a union type. The 'satisfies' usage here is intentional and correct for type checking. Could there be a valid reason to prefer 'as' over 'satisfies' in this codebase that I'm not aware of? Maybe there's a style guide or pattern established elsewhere? Even if there were a style preference elsewhere, the consistent use of 'satisfies' in this file for ReactiveFlags assertions suggests this is the intended pattern, and the comment would be disruptive to this consistency. The comment should be deleted as it's incorrect - the code is using 'satisfies' consistently and appropriately.
Workflow ID: wflow_O1xVEsqWhPExeFde
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please add a changeset file with feat: add computed peek
?
should be similar to https://raw.githubusercontent.com/un-ts/unuse/d9c6ae572a3e8437081ecc3bbbf50b8ca033ce53/.changeset/dark-rats-ask.md
This can be easily added on GitHub web UI, I'll add it. Actually no maintainer permission required. |
98b372a
to
72b889f
Compare
Important
Adds
peek()
method toUnComputed
for value retrieval without triggering effects, and removescomputedOper
function.peek()
method toUnComputed
inindex.ts
to retrieve current value without triggering effects.computedOper
function and integrates logic intoget()
method ofUnComputed
.peek()
method inindex.spec.ts
to ensure it retrieves value without triggering effects.peek()
method existence inUnComputed
objects.This description was created by
for 44e5ba7. You can customize this summary. It will automatically update as commits are pushed.
Summary by CodeRabbit
New Features
Refactor
Tests