| null }), withComputed((store, globalProductsStore = inject(GlobalProductsStore)) => ({ productDetail: computed(() => { const productId = store.productId(); const existingProduct = globalProductsStore.products() .find(x => x.id === productId); return existingProduct ?? null; }) })), withMethods( ( store, globalCheckoutStore = inject(GlobalCheckoutStore), globalProductsStore = inject(GlobalProductsStore), productDetailService = inject(ProductDetailService) ) => ({ addToCart: globalCheckoutStore.addToCart, loadProductIfNotLoaded: rxMethod<string>( pipe( tap((productId) => patchState(store, { productId })), 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 withState({ productId: null as string | null }), export const ProductDetailStore = signalStore( 1 2 3 4 withComputed((store, globalProductsStore = inject(GlobalProductsStore)) => ({ 5 productDetail: computed(() => { 6 const productId = store.productId(); 7 const existingProduct = globalProductsStore.products() 8 .find(x => x.id === productId); 9 10 return existingProduct ?? null; 11 }) 12 })), 13 withMethods( 14 ( 15 store, 16 globalCheckoutStore = inject(GlobalCheckoutStore), 17 globalProductsStore = inject(GlobalProductsStore), 18 productDetailService = inject(ProductDetailService) 19 ) => ({ 20 addToCart: globalCheckoutStore.addToCart, 21 loadProductIfNotLoaded: rxMethod<string>( 22 pipe( 23 tap((productId) => patchState(store, { productId })), 24 withComputed((store, globalProductsStore = inject(GlobalProductsStore)) => ({ productDetail: computed(() => { const productId = store.productId(); const existingProduct = globalProductsStore.products() .find(x => x.id === productId); return existingProduct ?? null; }) })), export const ProductDetailStore = signalStore( 1 withState({ 2 productId: null as string | null 3 }), 4 5 6 7 8 9 10 11 12 13 withMethods( 14 ( 15 store, 16 globalCheckoutStore = inject(GlobalCheckoutStore), 17 globalProductsStore = inject(GlobalProductsStore), 18 productDetailService = inject(ProductDetailService) 19 ) => ({ 20 addToCart: globalCheckoutStore.addToCart, 21 loadProductIfNotLoaded: rxMethod<string>( 22 pipe( 23 tap((productId) => patchState(store, { productId })), 24 loadProductIfNotLoaded: rxMethod<string>( export const ProductDetailStore = signalStore( 1 withState({ 2 productId: null as string | null 3 }), 4 withComputed((store, globalProductsStore = inject(GlobalProductsStore)) => ({ 5 productDetail: computed(() => { 6 const productId = store.productId(); 7 const existingProduct = globalProductsStore.products() 8 .find(x => x.id === productId); 9 10 return existingProduct ?? null; 11 }) 12 })), 13 withMethods( 14 ( 15 store, 16 globalCheckoutStore = inject(GlobalCheckoutStore), 17 globalProductsStore = inject(GlobalProductsStore), 18 productDetailService = inject(ProductDetailService) 19 ) => ({ 20 addToCart: globalCheckoutStore.addToCart, 21 22 pipe( 23 tap((productId) => patchState(store, { productId })), 24 tap((productId) => patchState(store, { productId })), export const ProductDetailStore = signalStore( 1 withState({ 2 productId: null as string | null 3 }), 4 withComputed((store, globalProductsStore = inject(GlobalProductsStore)) => ({ 5 productDetail: computed(() => { 6 const productId = store.productId(); 7 const existingProduct = globalProductsStore.products() 8 .find(x => x.id === productId); 9 10 return existingProduct ?? null; 11 }) 12 })), 13 withMethods( 14 ( 15 store, 16 globalCheckoutStore = inject(GlobalCheckoutStore), 17 globalProductsStore = inject(GlobalProductsStore), 18 productDetailService = inject(ProductDetailService) 19 ) => ({ 20 addToCart: globalCheckoutStore.addToCart, 21 loadProductIfNotLoaded: rxMethod<string>( 22 pipe( 23 24 export const ProductDetailStore = signalStore( 1 withState({ 2 productId: null as string | null 3 }), 4 withComputed((store, globalProductsStore = inject(GlobalProductsStore)) => ({ 5 productDetail: computed(() => { 6 const productId = store.productId(); 7 const existingProduct = globalProductsStore.products() 8 .find(x => x.id === productId); 9 10 return existingProduct ?? null; 11 }) 12 })), 13 withMethods( 14 ( 15 store, 16 globalCheckoutStore = inject(GlobalCheckoutStore), 17 globalProductsStore = inject(GlobalProductsStore), 18 productDetailService = inject(ProductDetailService) 19 ) => ({ 20 addToCart: globalCheckoutStore.addToCart, 21 loadProductIfNotLoaded: rxMethod<string>( 22 pipe( 23 tap((productId) => patchState(store, { productId })), 24 exhaustMap((id) => productDetailService.loadProductDetail(id).pipe( tapResponse({ next: (product) => globalProductsStore.add(product), error: console.error }) ) ) store, 16 globalCheckoutStore = inject(GlobalCheckoutStore), 17 globalProductsStore = inject(GlobalProductsStore), 18 productDetailService = inject(ProductDetailService) 19 ) => ({ 20 addToCart: globalCheckoutStore.addToCart, 21 loadProductIfNotLoaded: rxMethod<string>( 22 pipe( 23 tap((productId) => patchState(store, { productId })), 24 filter((productId) => !globalProductsStore.products() 25 .find(x => x.id === productId)), 26 27 28 29 30 31 32 33 34 ) 35 ) 36 }) 37 ) 38 ); 39