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(signals): add withProps base feature #4607

Merged
merged 4 commits into from
Nov 28, 2024
Merged

Conversation

markostanimirovic
Copy link
Member

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?

  • 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.

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),
    })),
  );
}

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),
    })),
  );
}
Copy link

netlify bot commented Nov 26, 2024

Deploy Preview for ngrx-io ready!

Name Link
🔨 Latest commit d2a1307
🔍 Latest deploy log https://app.netlify.com/sites/ngrx-io/deploys/674791de0cd07f000839f3d6
😎 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.

@jits
Copy link
Contributor

jits commented Nov 26, 2024

Amazing work! 🎉

Copy link
Contributor

@rainerhahnekamp rainerhahnekamp left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Most changes are renaming to props. The main addition is withProps with updates to withComputed. Way to go! 👍

@timdeschryver timdeschryver merged commit e626082 into main Nov 28, 2024
11 checks passed
@timdeschryver timdeschryver deleted the feat/with-props branch November 28, 2024 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC(@ngrx/signals): Add withProps feature
4 participants