Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
import { config } from '@skava/di'
import { WebClientExports } from './typings'

const scoped = Object.seal({
  OmniStore: undefined,
  client: undefined,
  App: undefined,
})
// default it to this for now
if (process.env.MOCK_CLIENT_DEPS_ON_SERVER || true) {
  console.log('[react-server] mocking client')
  scoped.App = () => 'no ssr'
  scoped.client = {
    extract() {
      return {
        // extracted
      }
    },
  }
  scoped.OmniStore = {
    create() {
      return {
        // created
      }
    },
  }
}

/**
 * @see https://www.apollographql.com/docs/react/features/server-side-rendering.html#server-initialization
 */
export function requireClient(): WebClientExports {
  if (process.env.REQUIRE_CLIENT_UNCACHED) {
    throw new Error(
      'requiring uncached client unsupported. please do not use REQUIRE_CLIENT_UNCACHED'
    )
  } else {
    console.log('[react-server] getting dependencies from @skava/di')

    if (config.has('OmniStore') === true) {
      scoped.OmniStore = config.get('OmniStore')
    }
    if (config.has('client') === true) {
      scoped.client = config.get('client')
    }
    if (config.has('App') === true) {
      scoped.App = config.get('App')
    }
  }

  return scoped
}