Create signal store

From FabianGosebrink/dog-rate-app · View interactive version

Create signal store is an AI agent skill from the GitHub repository FabianGosebrink/dog-rate-app. Use when the user asks to add state management or create a store for a feature in this Angular workspace.

How to use this skill

Skill file

Creating a Signal Store

In this workspace we manage state exclusively with the NgRx Signal Store.

When asked to create a store, follow these rules:

placement test in the state-management skill — don't default to root.

with withState({ ... }).

call in tapResponse. Track loading with a loading flag kept in

withState({ loading: false }): set it to true before the call in a

leading tap, and back to false when the data arrives.

injected NotificationService. On error, show an error notification.

a withHooks({ onInit }) hook.

Example

export const DogsStore = signalStore(
  { providedIn: 'root' },
  withEntities<Dog>(),
  withState({ loading: false }),
  withMethods(
    (
      store,
      notificationService = inject(NotificationService),
      dogsApiService = inject(DogsApiService),
    ) => ({
      loadDogs: rxMethod<void>(
        pipe(
          tap(() => patchState(store, { loading: true })),
          exhaustMap(() =>
            dogsApiService.getDogs().pipe(
              tapResponse({
                next: (dogs) => {
                  patchState(store, setAllEntities(dogs), { loading: false });
                  notificationService.showSuccess('Dogs Loaded');
                },
                error: () => notificationService.showError(),
              }),
            ),
          ),
        ),
      ),
    }),
  ),
  withHooks({
    onInit(store) {
      store.loadDogs();
    },
  }),
);
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.