()
| 109 | }; |
| 110 | |
| 111 | initialize() { |
| 112 | const targetWindow = this.props.targetWindow || window; |
| 113 | |
| 114 | invariant( |
| 115 | typeof targetWindow.matchMedia === "function", |
| 116 | "<Media targetWindow> does not support `matchMedia`." |
| 117 | ); |
| 118 | |
| 119 | const queries = this.props.queries || wrapInQueryObject(this.props.query); |
| 120 | |
| 121 | this.queries = Object.keys(queries).map(name => { |
| 122 | const query = queries[name]; |
| 123 | const qs = typeof query !== "string" ? json2mq(query) : query; |
| 124 | const mqListener = new MediaQueryListener( |
| 125 | targetWindow, |
| 126 | qs, |
| 127 | this.updateMatches |
| 128 | ); |
| 129 | |
| 130 | return { name, mqListener }; |
| 131 | }); |
| 132 | } |
| 133 | |
| 134 | componentDidMount() { |
| 135 | this.initialize(); |
no test coverage detected