(contextKey)
| 49 | ) |
| 50 | |
| 51 | const createContextSubscriber = (contextKey) => ( |
| 52 | |
| 53 | class Subscriber extends React.Component { |
| 54 | |
| 55 | static propTypes = { |
| 56 | children: PropTypes.func |
| 57 | } |
| 58 | |
| 59 | static contextTypes = { |
| 60 | [contextKey]: PropTypes.object |
| 61 | } |
| 62 | |
| 63 | constructor(props, context) { |
| 64 | super() |
| 65 | const emitter = context[contextKey] |
| 66 | if (emitter) { |
| 67 | this.state = { |
| 68 | value: emitter.getInitialValue() |
| 69 | } |
| 70 | this.unsubscribe = emitter.subscribe((value) => { |
| 71 | this.setState({ value }) |
| 72 | }) |
| 73 | } else { |
| 74 | this.state = {} |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | componentWillUnmount() { |
| 79 | this.unsubscribe() |
| 80 | } |
| 81 | |
| 82 | render() { |
| 83 | return this.props.children(this.state.value) |
| 84 | } |
| 85 | |
| 86 | } |
| 87 | ) |
| 88 | |
| 89 | export { createContextEmitter, createContextSubscriber } |
no outgoing calls
no test coverage detected
searching dependent graphs…