Sensors
Inglorious Web exposes browser sensor state as entity types, so live browser data stays in the store instead of being scattered across event listeners in your app.
Sensor entities are designed to keep the entity state serializable by storing runtime listeners and observers outside the entity itself.
Built-in sensors
Compass— device orientation and heading stateGeolocation— browser position and watch stateElementSize— DOM element resize tracking viaResizeObserverNetworkStatus— online/offline connectivity statePageVisibility— page visibility state fromdocument.visibilityStateMediaQuery— media query matching withwindow.matchMedia
Why use sensor entities
- Serializable state — runtime listeners and observers are kept outside the entity object
- Centralized behavior — sensor lifecycle and normalization logic live in one place
- Reactive UI — sensor state updates flow through the store naturally
- Testable — sensors can be exercised through store events and state assertions
Common sensor patterns
Most sensors support:
isSupported— feature detection for the current environmentisWatching— whether the sensor is actively listening- normalized sensor state exposed on the entity
- explicit watch/unwatch lifecycle management
Example
javascript
import { createStore } from "@inglorious/store"
import { MediaQuery } from "@inglorious/web/sensors/media-query"
const store = createStore({
types: { MediaQuery },
autoCreateEntities: true,
})
const mediaQuery = store.getEntity("mediaQuery")
if (mediaQuery.matches) {
// render desktop layout
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
Inglorious Web