8000 feat: add computed peek by teleskop150750 · Pull Request #66 · un-ts/unuse · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Conversation

teleskop150750
Copy link
Contributor
@teleskop150750 teleskop150750 commented Jul 4, 2025

Important

Adds peek() method to UnComputed for value retrieval without triggering effects, and removes computedOper function.

  • Behavior:
    • Adds peek() method to UnComputed in index.ts to retrieve current value without triggering effects.
    • Removes computedOper function and integrates logic into get() method of UnComputed.
  • Tests:
    • Adds test for peek() method in index.spec.ts to ensure it retrieves value without triggering effects.
    • Updates existing tests to check for peek() method existence in UnComputed objects.

This description was created by Ellipsis for 44e5ba7. You can customize this summary. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • New Features

    • Introduced a peek method for computed values, allowing users to access the current value without triggering reactive effects.
  • Refactor

    • Streamlined the internal logic for retrieving computed values by inlining the retrieval method.
  • Tests

    • Added and updated tests to verify the behavior of the peek method and ensure correct functionality.

Copy link
changeset-bot bot commented Jul 4, 2025

🦋 Changeset detected

Latest commit: 72b889f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
unuse-reactivity Minor
unuse Minor
unuse-angular Minor
unuse-react Minor
unuse-solid Minor
unuse-vue Minor

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

Copy link
coderabbitai bot commented Jul 4, 2025

Walkthrough

The unComputed reactive primitive was refactored to inline its computed value retrieval logic and introduce a new peek method for non-reactive access. Tests were updated to verify the presence and behavior of the new peek method, ensuring it does not trigger reactive effects.

Changes

File(s) Change Summary
packages/unuse-reactivity/src/unComputed/index.ts Inlined computed value retrieval logic into get, removed computedOper, and added a peek method.
packages/unuse-reactivity/src/unComputed/index.spec.ts Updated tests to verify peek method existence and behavior, and imported unEffect for testing.

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)
Loading

Possibly related PRs

Suggested labels

feature

Poem

In the garden of code where signals bloom,
A rabbit peeks—no reactive doom!
With logic inlined and te 8000 sts anew,
The value is fetched, but no effect grew.
Hop, hop, hooray, for peek saves the day!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 44e5ba7 and 98b372a.

📒 Files selected for processing (1)
  • .changeset/neat-dots-hug.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .changeset/neat-dots-hug.md
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor
github-actions bot commented Jul 4, 2025

Coverage Report

Status Category Percentage Covered / Total
🔴 Lines 81.38% (🎯 90%)
⬆️ +0.06%
1237 / 1520
🔴 Statements 81.38% (🎯 90%)
⬆️ +0.06%
1237 / 1520
🔴 Functions 77.88% (🎯 90%)
⬆️ +0.22%
81 / 104
🔴 Branches 83.75% (🎯 85%)
⬆️ +0.04%
330 / 394
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/unuse-reactivity/src/unComputed/index.ts 88.67%
⬆️ +1.17%
82.35%
⬆️ +1.10%
100%
🟰 ±0%
88.67%
⬆️ +1.17%
74-75, 78-79, 84-85
Unchanged Files
packages/unuse-angular/src/index.ts 94.2% 100% 83.33% 94.2% 143-146
packages/unuse-react/src/index.ts 69.86% 68.18% 100% 69.86% 49-55, 58-71, 139-143, 152
packages/unuse-reactivity/src/index.ts 0% 0% 0% 0% 1-5
packages/unuse-reactivity/src/unEffect/index.ts 95.65% 66.66% 100% 95.65% 26
packages/unuse-reactivity/src/unEffectScope/index.ts 90.9% 50% 100% 90.9% 24-25
packages/unuse-reactivity/src/unReactiveSystem/index.ts 84.76% 88% 66.66% 84.76% 38-44, 68-69, 80-81, 92-93, 96-97, 100-103, 154-155, 188-189
packages/unuse-reactivity/src/unSignal/index.ts 100% 100% 100% 100%
packages/unuse-reactivity/src/unWatch/index.ts 100% 100% 100% 100%
packages/unuse-solid/src/index.ts 83.09% 86.95% 100% 83.09% 52-59, 69, 141-145
packages/unuse-vue/src/index.ts 100% 100% 100% 100%
packages/unuse/src/index.ts 0% 0% 0% 0% 1-15
packages/unuse/src/_framework/index.ts 81.53% 62.5% 100% 81.53% 48-49, 67-68, 76-77, 85-86, 94-95, 102-103
packages/unuse/src/_testUtils/angular.ts 100% 100% 100% 100%
packages/unuse/src/_testUtils/react.ts 100% 100% 100% 100%
packages/unuse/src/_testUtils/solid.ts 100% 100% 100% 100%
packages/unuse/src/_testUtils/vue.ts 100% 100% 100% 100%
packages/unuse/src/isClient/index.ts 100% 0% 100% 100%
packages/unuse/src/isObject/index.ts 100% 100% 100% 100%
packages/unuse/src/isWorker/index.ts 66.66% 0% 100% 66.66% 5
packages/unuse/src/toArray/index.ts 100% 50% 100% 100%
packages/unuse/src/toUnSignal/index.ts 80.7% 83.33% 66.66% 80.7% 17-18, 31-32, 35-36, 43-44, 81-87, 98-99, 113-120, 130
packages/unuse/src/tryOnScopeDispose/index.ts 77.77% 78.57% 50% 77.77% 11-14, 23-24, 35-36, 40-41
packages/unuse/src/unAccess/index.ts 73% 80% 66.66% 73% 43-44, 48-49, 66-67, 71, 80-81, 84-93, 97-98, 104-105, 114-115, 118-119, 122-123
packages/unuse/src/unRefElement/index.ts 75% 33.33% 100% 75% 29, 36-37
packages/unuse/src/unResolve/index.ts 92.66% 97.14% 71.42% 92.66% 71-72, 93-94, 125-128
packages/unuse/src/useEventListener/index.ts 96.34% 86.66% 100% 96.34% 192-193, 198
packages/unuse/src/useIntervalFn/index.ts 92.85% 80% 100% 92.85% 77-78, 82-83
packages/unuse/src/useToggle/index.ts 100% 100% 100% 100%
packages/unuse/src/useWebSocket/index.ts 46.66% 41.66% 33.33% 46.66% 161-163, 203-212, 216-218, 222-224, 233-235, 244-256, 262-263, 270-275, 278-308, 311-312, 315-326, 330-355, 367-368
Generated in workflow #171 for commit 72b889f by the Vitest Coverage Report Action

Copy link
Contributor
@ellipsis-dev ellipsis-dev bot left a 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 in 2 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 Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

JounQin
JounQin previously approved these changes Jul 4, 2025
@Shinigami92 Shinigami92 changed the title feat(reactivity): [unComputed] peek feat: unComputed peek Jul 4, 2025
@Shinigami92 Shinigami92 changed the title feat: unComputed peek feat: add computed peek Jul 4, 2025
Copy link
Member
@Shinigami92 Shinigami92 left a 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

@JounQin
Copy link
Member
JounQin commented Jul 4, 2025

could you please add a changeset file with feat: add computed peek?

should be similar to d9c6ae5/.changeset/dark-rats-ask.md (raw)

This can be easily added on GitHub web UI, I'll add it.

image

Actually no maintainer permission required.

JounQin
JounQin previously approved these changes Jul 4, 2025
@JounQin JounQin force-pushed the refactor/reactivity_02 branch from 98b372a to 72b889f Compare July 4, 2025 10:31
@JounQin JounQin enabled auto-merge July 4, 2025 10:33
@JounQin JounQin added this pull request to the merge queue Jul 4, 2025
Merged via the queue into un-ts:main with commit 2b65507 Jul 4, 2025
17 checks passed
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.

3 participants
0