Giter Site home page Giter Site logo

oc-template-react's Introduction

oc-template-react

react-templates & utilties for the OpenComponents template system


Module for handling React templates in OC

Build Status codecov Known Vulnerabilities npm version

Packages included in this repo

Name Version
oc-template-react npm version
oc-template-react-compiler npm version
oc-react-component-wrapper npm version

Usage:

Initialize a component with the oc-template-react and follow the CLI instructions

$ oc init <your-component-name> oc-template-react

Extra info:

package.json requirements

  • template.src - the react App entry point - should export a react component as default
  • template.type - oc-template-react
  • required in devDependencies - oc-template-react-compiler

conventions

  • props = server() - the viewModel generated by the server is automatically passed to the react application as props
  • The oc-client-browser is extended and will now expose all the available react-component at oc.reactComponents[bundleHash]

externals

Externals are not bundled when packaging and publishing the component, for better size taking advantage of externals caching. OC will make sure to provide them at Server-Side & Client-Side rendering time for you.

  • React
  • ReactDOM
  • PropTypes

features

Utils

The compiler exposes some utilities that could be used by your React application:

HOCs

withDataProvider

An Higher order component that will make a getData function available via props.

Usage:
import { withDataProvider } from 'oc-template-react-compiler/utils';

const yourApp = props => {
  // you can use props.getData here
};

yourEnhancedApp = withDataProvider(yourApp);

getData accept two arguments: (params, callback) => callback(err, result). It will perform a post back request to the component endpoint with the specified query perams invoking the callback with the results.

For more details, check the example app

withSettingProvider

An Higher order component that will make a getSetting function available via props.

Usage:
import { withSettingProvider } from 'oc-template-react-compiler/utils';

const yourApp = props => {
  // you can use props.getSetting here
};

yourEnhancedApp = withSettingProvider(yourApp);

getSetting accept one argument: settingName => settingValue. It will return the value for the requested setting.

Settings available at the moment:

  • getSetting('name') : return the name of the OC component
  • getSetting('version') : return the version of the OC component
  • getSetting('baseUrl') : return the baseUrl of the oc-registry
  • getSetting('staticPath') : return the path to the static assets of the OC component

oc-template-react's People

Contributors

nickbalestra avatar matteofigus avatar dependencies-bot avatar arnoldzokas avatar davegaeddert avatar dipunm avatar kmcrawford avatar pbazydlo avatar

Watchers

James Cloos avatar Steven Bassett avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.