Check if the current viewport size is in the desktop category
Desktop size typically indicates a large screen with ample horizontal space for full-featured layouts, multiple columns, and detailed information display.
true if the viewport is desktop-sized, false otherwise
Check if the current viewport size is in the phone category
Phone size typically indicates a small screen where compact layouts, single columns, and simplified navigation patterns are most appropriate.
true if the viewport is phone-sized, false otherwise
Check if the current viewport size is in the tablet category
Tablet size typically indicates a medium-sized screen where some layout adjustments may be needed compared to desktop, but more space is available than on phone screens.
true if the viewport is tablet-sized, false otherwise
Subscribe to state changes with optional transformation and filtering.
The subscription will immediately invoke the callback with the current state (if any), then continue to call it whenever the state changes. The map and filter options allow you to transform and selectively receive updates.
Unsubscribe function - call this to stop receiving updates
// Basic subscription
const unsubscribe = repository.subscribe((state) => {
console.log('State updated:', state);
});
// With transformations
const unsubscribe = repository.subscribe(
(userName) => console.log('User:', userName),
{ map: [(state) => state.user?.name] }
);
Function called with state updates (after map/filter applied)
Rest ...args: unknown[]Optional options: StateOptionsOptional transformations and filters for the subscription
Subscribe to state changes with optional transformation and filtering.
The subscription will immediately invoke the callback with the current state (if any), then continue to call it whenever the state changes. The map and filter options allow you to transform and selectively receive updates.
Unsubscribe function - call this to stop receiving updates
// Basic subscription
const unsubscribe = repository.subscribe((state) => {
console.log('State updated:', state);
});
// With transformations
const unsubscribe = repository.subscribe(
(userName) => console.log('User:', userName),
{ map: [(state) => state.user?.name] }
);
Service for detecting the current device viewport size category
The Device service provides reactive methods to determine whether the current viewport size falls into desktop, tablet, or phone categories. This is useful for creating responsive components that adapt their UI based on available screen real estate.
Since Device extends StateRepository, components can use the
@Statedecorator to automatically re-render when the device size category changes (e.g., when the user resizes their browser window or rotates their device).Example
Checking device size
Example
Conditional logic based on viewport size