ngrx / platform

Reactive State for Angular
https://ngrx.io
Other
8.05k stars 1.98k forks source link

feat(signals): add `withProps` base feature #4607

Open markostanimirovic opened 4 hours ago

markostanimirovic commented 4 hours ago

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?

Closes #4504

What is the new behavior?

Does this PR introduce a breaking change?

[x] Yes
[ ] No
BREAKING CHANGES:

- The `computed` property in `SignalStoreFeatureResult` type is renamed to `props`.
- The `EntityComputed` and `NamedEntityComputed` types in the `entities` plugin are renamed to `EntityProps` and `NamedEntityProps`.

BEFORE:

import { computed, Signal } from '@angular/core';
import {
  signalStoreFeature,
  SignalStoreFeature,
  type,
  withComputed,
} from '@ngrx/signals';
import { EntityComputed } from '@ngrx/signals/entities';

export function withTotalEntities<Entity>(): SignalStoreFeature
  { state: {}, computed: EntityComputed<Entity>, methods: {} },
  { state: {}, computed: { total: Signal<number> }, methods: {} },
> {
  return signalStoreFeature(
    { computed: type<EntityComputed<Entity>>() },
    withComputed(({ entities }) => ({
      total: computed(() => entities().length),
    })),
  );
}

AFTER:

import { computed, Signal } from '@angular/core';
import {
  signalStoreFeature,
  SignalStoreFeature,
  type,
  withComputed,
} from '@ngrx/signals';
import { EntityProps } from '@ngrx/signals/entities';

export function withTotalEntities<Entity>(): SignalStoreFeature
  { state: {}, props: EntityProps<Entity>, methods: {} },
  { state: {}, props: { total: Signal<number> }, methods: {} },
> {
  return signalStoreFeature(
    { props: type<EntityProps<Entity>>() },
    withComputed(({ entities }) => ({
      total: computed(() => entities().length),
    })),
  );
}
netlify[bot] commented 4 hours ago

Deploy Preview for ngrx-io ready!

Name Link
Latest commit 9fee29d88e13da6e1d64e81a6672987c6c8d3911
Latest deploy log https://app.netlify.com/sites/ngrx-io/deploys/674537e40854d40008d34e8e
Deploy Preview https://deploy-preview-4607--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.