Grilled Cheese

ExploreLog inSign up
Terms of UsePrivacy PolicyCommunity StandardsHelpGet the app

Grilled Cheese is a product of Village Compute

Version devBuilt at: 2026-12-03 22:42:33 EST

PhotosVideosAllPeople
LatestRanked
import { unprotected } from '@ngrx/signals/testing';

const store = TestBed.inject(CartStore);
patchState(unprotected(store), {
  items: [{ id: '1', name: 'Keyboard', price: 99 }],
});
// Global singleton (auth, feature flags, cart)
export const AppStore = signalStore(
  { providedIn: 'root' },
  withState({ user: null as User | null }),
);

// Scoped per component (auto-destroyed on leave)
@Component({ providers: [CheckoutStore], template: `...` })
export class CheckoutPage { store = inject(CheckoutStore); }
Quiz infographic: Match three RxJS flattening operators — 1 switchMap (cancel previous, run latest), 2 exhaustMap (ignore new until current finishes), 3 concatMap (queue and run in strict order) — to three shuffled use cases: A Checkout / Pay Now button double-click, B Ordered autosave queue, C Search-as-you-type.
export const CartStore = signalStore(
  withState({ items: [] as Item[] }),
  withComputed((store, auth = inject(AuthStore)) => ({
    discount: computed(() =>
      auth.isPro() ? store.subtotal() * 0.2 : 0
    ),
  })),
);
TypeScript code in a dark editor tab named notifications.store.ts. A Notification interface has id, text and read. NotificationsStore is a signalStore with withEntities<Notification>(), a computed unread count of entities that are not read, and two methods: markAllRead calls patchState(store, updateAllEntities({ read: true })), highlighted, and clearRead calls patchState with removeEntities((n) => n.read), also highlighted.
Angular code in a dark editor tab named product-filters.ts. A Sort type is 'price' or 'rating'. A ProductFilters component's template has an input bound to filters.query() that calls search($event), and a paragraph "Sorted by" filters.sort(). The class field filters = signalState({ query: '', sort: 'price' as Sort, inStock: false }) is highlighted, and the search method reads the input value and calls patchState(this.filters, { query }), also highlighted.
TypeScript code in a dark editor tab named todos.store.ts. A TodosStore is created with signalStore and state todos. A highlighted withProps block adds api: inject(TodosApi) and pageSize: 20. Below, withMethods defines an async load(page) method that calls store.api.load({ page, size: store.pageSize }), highlighted, and patches the todos into state.
TypeScript code in a dark editor tab named cart.store.ts. An NgRx CartStore uses withEntities for cart items and withState with drawerOpen: false. Its one method, addToCart(product), highlighted with the comment "what the user did: adds the item and opens the cart drawer", raises the quantity if the product is already in the cart or adds it with quantity 1, and sets drawerOpen to true in the same patchState call. A last comment shows a component only calling cart.addToCart(product) from an Add to cart button.
"Hands on: NgRx Toolkit! Supercharging SignalStore", November 4, 4:30 PM UTC. Host Armen Vardanyan on a purple space background, with the Angular Space TV and Angular logos.
"Hands on: NgRx Toolkit! Supercharging SignalStore", November 4, 4:30 PM UTC. Host Armen Vardanyan on a purple space background, with the Angular Space TV and Angular logos.
An NgRx Signal Store in cart.store.ts. Line 9, highlighted, mutates the array in place inside patchState:

export const CartStore = signalStore(
  withState({ items: [] as Item[] }),
  withComputed((store) => ({
    count: computed(() => store.items().length),
  })),
  withMethods((store) => ({
    addItem(item: Item) {
      patchState(store, (state) => {
        state.items.push(item); // same array, new contents
        return { items: state.items };
      });
    },
  })),
);

// After calling addItem() twice:
// the list renders 2 items, but count() is still 0
export const cartEvents = eventGroup({ source: 'Cart Page', events: {
  added: type<CartItem>(), removed: type<number>(),
} });
export const CartStore = signalStore(
  withState({ items: [] as CartItem[] }),
  withReducer(
    on(cartEvents.added, ({ payload }, { items }) => ({ items: [...items, payload] })),
    on(cartEvents.removed, ({ payload }, { items }) => ({ items: items.filter((i) => i.id !== payload) })),
  ),
);