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 entityConfig function #4399

Merged
merged 1 commit into from
Jun 29, 2024

Conversation

markostanimirovic
Copy link
Member

@markostanimirovic markostanimirovic commented Jun 15, 2024

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?

const selectId: SelectEntityId<Todo> = (todo) => todo.key;

const Store = signalStore(
  withEntities({ entity: type<Todo>(), collection: 'todo' }),
  withEntities({ entity: type<User>(), collection: 'user' }),
  withMethods((store) => ({
    addTodo(todo: Todo): void {
      patchState(store, addEntity(todo, { collection: 'todo', selectId }));
    },
    addUser(user: User): void {
      patchState(store, addEntity(user, { collection: 'user' }));
    },
  }))
);

Closes #4393

What is the new behavior?

const todoConfig = entityConfig({
  entity: type<Todo>(),
  collection: 'todo',
  selectId: (todo) => todo.key,
});

const userConfig = entityConfig({
  entity: type<User>(),
  collection: 'user',
});

const Store = signalStore(
  withEntities(todoConfig),
  withEntities(userConfig),
  withMethods((store) => ({
    addTodo(todo: Todo): void {
      patchState(store, addEntity(todo, todoConfig));
    },
    addUser(user: User): void {
      patchState(store, addEntity(user, userConfig));
    },
  }))
);

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Copy link

netlify bot commented Jun 15, 2024

Deploy Preview for ngrx-io ready!

Name Link
🔨 Latest commit 49b0ca0
🔍 Latest deploy log https://app.netlify.com/sites/ngrx-io/deploys/667fefe5bd48fb00083254fc
😎 Deploy Preview https://deploy-preview-4399--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.

@markostanimirovic markostanimirovic force-pushed the feat/signals/entity-meta branch 2 times, most recently from 1c66d05 to c6ce12e Compare June 17, 2024 17:11
modules/signals/entities/src/entity-meta.ts Outdated Show resolved Hide resolved
@markostanimirovic markostanimirovic changed the title feat(signals): add entityMeta function feat(signals): add entityConfig function Jun 29, 2024
@markostanimirovic markostanimirovic merged commit 1b1cf5b into main Jun 29, 2024
4 of 5 checks passed
@markostanimirovic markostanimirovic deleted the feat/signals/entity-meta branch June 29, 2024 11:57
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.

@ngrx/signals/entity: Introduce entityConfig function
5 participants