Last active
          January 19, 2018 20:11 
        
      - 
      
- 
        Save damassi/8bbcc8179a0a4d2513e254737420c1e1 to your computer and use it in GitHub Desktop. 
    Stub Relay so that `react-relay` HOC components can accept raw data rather than using Relay network layer
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | render () { | |
| const artwork = { name: 'Banksy' } | |
| return ( | |
| <RelayStubProvider> | |
| <Artwork artwork={artwork} /> | |
| </RelayStubProvider> | |
| ) | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import PropTypes from 'prop-types' | |
| import { Component } from 'react' | |
| import { Environment, Network, RecordSource, Store } from 'relay-runtime' | |
| export class RelayStubProvider extends Component { | |
| static propTypes = { | |
| children: PropTypes.node.isRequired, | |
| relay: PropTypes.object | |
| } | |
| static defaultProps = { | |
| relay: { | |
| environment: new Environment({ | |
| network: Network.create(x => x), | |
| store: new Store(new RecordSource()) | |
| }), | |
| variables: {} | |
| } | |
| } | |
| static childContextTypes = { | |
| relay: PropTypes.object.isRequired | |
| } | |
| getChildContext () { | |
| return { | |
| relay: this.props.relay | |
| } | |
| } | |
| render () { | |
| return this.props.children | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment