
ALT TypeScript code in a dark editor tab named orders.ts. A pageVisible() function returns toSignal of fromEvent(document, 'visibilitychange'), highlighted, mapped to document.visibilityState === 'visible', with startWith for the current state and requireSync: true. Below, an Orders component shows the number of orders from httpResource('/api/orders'). Its constructor runs an effect with the comment "fresh data when the user comes back to the tab": if this.visible(), it calls this.orders.reload(), both lines highlighted.
![TypeScript code in a dark editor tab named cart.service.ts. A CartService keeps a private writable signal _items and exposes it as items = this._items.asReadonly(), highlighted. It also has a computed total of the item prices and an add(item) method that updates _items. Below, a CartBadge component injects CartService and shows the item count and total. Its clear() method calls this.cart.items.set([]), highlighted with the comment "Error: Property 'set' does not exist on type 'Signal<CartItem[]>'".](https://pbs.twimg.com/media/HXPWOjbWgAAgcf8.jpg?name=small&format=webp)
ALT TypeScript code in a dark editor tab named cart.service.ts. A CartService keeps a private writable signal _items and exposes it as items = this._items.asReadonly(), highlighted. It also has a computed total of the item prices and an add(item) method that updates _items. Below, a CartBadge component injects CartService and shows the item count and total. Its clear() method calls this.cart.items.set([]), highlighted with the comment "Error: Property 'set' does not exist on type 'Signal<CartItem[]>'".
![Angular TypeScript code in a dark editor tab named product-search.ts. First, search.worker.ts: a message listener that runs searchProducts on the incoming data and posts the result back on ports[0]. Then a helper, runInWorker, that creates a new MessageChannel, posts the data to the worker together with port2 (highlighted), and returns a Promise that resolves when port1 receives the answer. Then a ProductSearch component: its template has an input that sets the query signal and a @for loop over results.value() showing each product name. The class creates the worker with new Worker(new URL('./search.worker', import.meta.url)) (highlighted), a query signal, and a results resource with params set to the query and a loader that calls runInWorker with the worker and the params (highlighted).](https://pbs.twimg.com/media/HW2FiFOWAAEUuhb.jpg?name=small&format=webp)
ALT Angular TypeScript code in a dark editor tab named product-search.ts. First, search.worker.ts: a message listener that runs searchProducts on the incoming data and posts the result back on ports[0]. Then a helper, runInWorker, that creates a new MessageChannel, posts the data to the worker together with port2 (highlighted), and returns a Promise that resolves when port1 receives the answer. Then a ProductSearch component: its template has an input that sets the query signal and a @for loop over results.value() showing each product name. The class creates the worker with new Worker(new URL('./search.worker', import.meta.url)) (highlighted), a query signal, and a results resource with params set to the query and a loader that calls runInWorker with the worker and the params (highlighted).





























