Skip to content

feat(signals): allow access to methods in withComputed #4864

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

rainerhahnekamp
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

withComputed doesn't have access to methods

Closes #4846

What is the new behavior?

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Copy link

netlify bot commented Jul 3, 2025

Deploy Preview for ngrx-io ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit c1186a2
🔍 Latest deploy log https://app.netlify.com/projects/ngrx-io/deploys/686b9373cd232c0007de920c
😎 Deploy Preview https://deploy-preview-4864--ngrx-io.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

netlify bot commented Jul 3, 2025

Deploy Preview for ngrx-site-v19 ready!

Name Link
🔨 Latest commit c1186a2
🔍 Latest deploy log https://app.netlify.com/projects/ngrx-site-v19/deploys/686b93720563680008dd9ed6
😎 Deploy Preview https://deploy-preview-4864--ngrx-site-v19.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the withComputed feature to include store methods in its computed factory, and adds type-level tests to verify method access and state immutability.

  • Extend withComputed signature to include Input['methods'] in the store parameter
  • Add type tests ensuring computed factories can access props, state signals, and methods, and cannot patch state
  • Clean up imports in spec files for consistency

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
modules/signals/src/with-computed.ts Include Input['methods'] in the store type for withComputed
modules/signals/spec/with-computed.spec.ts Move and dedupe TestBed import
modules/signals/spec/types/with-computed.types.spec.ts Refactor imports and add code snippets testing method access and immutability
Comments suppressed due to low confidence (1)

modules/signals/spec/types/with-computed.types.spec.ts:16

  • The TestBed import is unused in the type-level tests—removing it can keep the imports focused and clear.
        import { TestBed } from '@angular/core/testing';

@@ -1,4 +1,5 @@
import { computed, signal } from '@angular/core';
import { TestBed } from '@angular/core/testing';
Copy link
Preview

Copilot AI Jul 3, 2025

Choose a reason for hiding this comment

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

The TestBed import is not used in this file—consider removing it to reduce clutter.

Copilot uses AI. Check for mistakes.

Copy link
Member

Choose a reason for hiding this comment

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

we can remove TestBed import if it's unused

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We actually use it. Don't know why Copilot has here a different opinion....

Copy link
Member

@markostanimirovic markostanimirovic left a comment

Choose a reason for hiding this comment

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

Documentation needs to be updated as well: https://ngrx.io/guide/signals/signal-store#defining-store-properties

No need to add additional examples, just update the following part: utilizing previously defined state signals and properties => utilizing previously defined state signals, properties, and methods

@@ -1,4 +1,5 @@
import { computed, signal } from '@angular/core';
import { TestBed } from '@angular/core/testing';
Copy link
Member

Choose a reason for hiding this comment

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

we can remove TestBed import if it's unused

rainerhahnekamp and others added 2 commits July 5, 2025 23:16
Co-authored-by: Marko Stanimirović <markostanimirovic95@gmail.com>
@rainerhahnekamp
Copy link
Contributor Author

@markostanimirovic, @timdeschryver, I think we are ready to go with that one.

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.

RFC(@ngr/signals): Allow withComputed to access store methods
2 participants