cerebral-module-useragent
A Cerebral module for everything user agent.
Concept
The useragent module puts information about the browser into your model, and it also updates this information when the size of the browser changes etc.
- UA parser: browser and device
- Window: size & orientation
- Media queries
- Feature detection
- Internet connectivity
Install
This is still alpha but to test the bleeding edge.
npm install cerebral-module-useragent@next --save
NOTE: If you need to update to a later @next release than execute above command again.
Setup
import {Controller} from 'cerebral'
import Useragent from 'cerebral-module-useragent'
const controller = Controller({
modules: {
useragent: Useragent({
media: {
small: '(min-width: 600px)',
medium: '(min-width: 1024px)',
large: '(min-width: 1440px)',
portrait: '(orientation: portrait)'
},
feature: true,
parse: {
browser: true,
device: true
},
offline: {
checkOnLoad: false,
interceptRequests: true,
reconnect: {
initialDelay: 3,
delay: 1.5
},
requests: false
},
window: true
})
}
})
Grabbing details from useragent
The useragent module will populate your model on the given namespace. All you need to do in your view layer is to grab whatever data you need from it, for example media:
export default connect({
media: 'useragent.media.*'
}, ...)