Skip to content
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

feat: add signalMethod (#4581) #4597

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rainerhahnekamp
Copy link
Contributor

signalMethod is a factory function to process side effects on Signals or static values.

It is similar to rxMethod but does not support RxJS.

signalMethod follows Angular's pattern of RxJS-less utilities for Signals, like resource and rxResource.

signalMethod expects a type and processor function:

const doubleLogger = signalMethod<number>(value => console.log(value * 2))

const value = signal(1);
doubleLogger(value); // tracks value and executes initially and on every change

It also supports static values, e.g., doubleLogger(1).

This PR also contains the documentation and tests.

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:

Closes #4581

What is the new behavior?

Does this PR introduce a breaking change?

[ ] Yes
[x] No

`signalMethod` is a factory function to process side effects on Signals or
static values.

It is similar to `rxMethod` but does not support RxJS.

`signalMethod` follows Angular's pattern of RxJS-less utilities for Signals,
like `resource` and `rxResource`.

`signalMethod` expects a type and processor function:

```typescript
const doubleLogger = signalMethod<number>(value => console.log(value * 2))

const value = signal(1);
doubleLogger(value); // tracks value and executes initially and on every change
```

It also supports static values, e.g., `doubleLogger(1)`.
Copy link

netlify bot commented Nov 17, 2024

Deploy Preview for ngrx-io ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit fc660b9
🔍 Latest deploy log https://app.netlify.com/sites/ngrx-io/deploys/673a2bd06b58d00008b9bc3b
😎 Deploy Preview https://deploy-preview-4597--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 site configuration.

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: method - rxMethod without RxJS
1 participant