🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

electrode-ui-config

Package Overview
Dependencies
Maintainers
3
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electrode-ui-config

Isomorphic UI config

latest
Source
npmnpm
Version
1.4.0
Version published
Weekly downloads
57
-84.59%
Maintainers
3
Weekly downloads
 
Created
Source

electrode-ui-config

Makes the ui section from your app config available to your UI code. It works isomorphically.

Install

npm install electrode-ui-config --save

Usage

To access the ui section from your app config, use electrode-ui-config.ui.

For example.

import Config from "electrode-ui-config";

export default class MyComponent extends React.Component {
  render() {
    if (Config.ui.doThis) {
      return <This></This>
    } else {
      return <That></That>
    }
  }
}

Utilities

This module provides the following utilities:

fullPath

fullPath(path)

It will join config.ui.basePath with path to make a full UI route path.

Params

  • path - the path to join with basePath

Returns

  • A full UI route path with basePath.
  • if path is empty, then basePath is returned.

fullApiPath

fullApiPath(path)

Joins config.ui.basePath, config.ui.apiPath and path to make a full API route path.
basePath defaults to "", apiPath defaults to "/api".

Params

  • path - the path to join with basePath and apiPath

Returns

  • A full API route path. If path is empty, then /<basePath>/<apiPath> is returned.

How it works

This package utilize a webpack feature which looks at the browser field in package.json and use that when bundling.

When running on server side, NodeJS require looks at the main field, which points to another file.

Other Requirements

The client side simply uses window.config to retrieve the config values. Your application needs to be an Electrode app that uses electrode-server and electrode-react-webapp, which sends ui section from your app config to the browser in the Index template.

See electrode server configuration for details on setting up config files for your app.

Configuration files

Sample:

{
  connections: {
    ...
  },
  plugins: {
    ...
  },
  ui: {

  }
}

Server side render specific config

Occasionally apps or components need access to different config on server and client. To do this, add a ssrUi property to the root level of the config object:

{
  ...
  ssrUi {
    foo: "ServerOnlyValue"
  },
  ui: {
    foo: "ClientOnlyValue"
  }
}

ssrUi properties will overwrite any matching properties defined in ui. Isomorphic code can use Config.ui and properties defined in both ssrUi and ui will only be available in the respective environments.

FAQs

Package last updated on 05 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts