travis-ci
36 of 43 branches covered (83.72%)
Branch coverage included in aggregate %.
69 of 70 relevant lines covered (98.57%)
36.81 hits per line
1 |
import PropTypes from 'prop-types'; |
6 all except 189.1 ✔ |
2 |
import channel from './channel'; |
6 all except 189.1 ✔ |
3 |
|
|
4 |
export default function createThemeListener(CHANNEL = channel) { |
|
5 |
const contextTypes = { |
72 all except 189.1 ✔ |
6 |
[CHANNEL]: PropTypes.object.isRequired, |
|
7 |
}; |
|
8 |
|
|
9 |
function initial(context) { |
|
10 |
if (!context[CHANNEL]) {
|
|
11 |
throw new Error( |
40✔ |
12 |
`[${this.displayName}] Please use ThemeProvider to be able to use WithTheme`, |
|
13 |
); |
|
14 |
} |
|
15 |
|
|
16 |
return context[CHANNEL].getState()
|
36 all except 189.1 ✔ |
17 |
} |
× |
18 |
|
|
19 |
function subscribe(context, cb) { |
|
20 |
if (context[CHANNEL]) {
|
|
21 |
return context[CHANNEL].subscribe(cb);
|
36 all except 189.1 ✔ |
22 |
} |
|
23 |
} |
|
24 |
|
|
25 |
function unsubscribe(context, subscriptionId) { |
|
26 |
if (context[CHANNEL]) {
|
|
27 |
context[CHANNEL].unsubscribe(subscriptionId); |
2 all except 189.1 ✔ |
28 |
} |
|
29 |
} |
|
30 |
|
|
31 |
return {
|
72 all except 189.1 ✔ |
32 |
contextTypes, |
|
33 |
initial, |
|
34 |
subscribe, |
|
35 |
unsubscribe, |
|
36 |
}; |
|
37 |
} |