Slide 12
Slide 12 text
A Comparison: State & Slices
@Injectable({ providedIn: 'root' })
export class HolidaysStore {
// State
readonly #state = signal({
holidays: [] as Holiday[],
favouriteIds: [] as number[],
filter: { query: '', type: 0 },
});
// Slices
holidays = computed(() => this.#state().holidays);
favouriteIds = computed(() => this.#state().favouriteIds);
filter = computed(() => this.#state().filter);
}
export const HolidayStore = signalStore(
{ providedIn: 'root' },
withState({
holidays: [] as Holiday[],
favouriteIds: [] as number[],
filter: { query: '', type: 0 },
})
);