Giter Site home page Giter Site logo

gmin2 / generator-react-sdk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from asyncapi/generator-react-sdk

0.0 0.0 0.0 1.07 MB

Generator React SDK enabling the AsyncAPI generator to support React as the rendering engine for templates.

License: Apache License 2.0

JavaScript 9.41% TypeScript 90.59%

generator-react-sdk's Introduction

AsyncAPI React SDK

AsyncAPI React SDK is a set of components/functions to use React as render engine in the Generator.

Installation

Run this command to install the SDK in your project:

npm install --save @asyncapi/generator-react-sdk

How it works

The process of creating content from React components consists of two main process: transpile and rendering.

The Transpile Process

The SDK has a custom transpiler which ensures that any directory are transpiled using Rollup. Rollup helps bundling all dependencies and transpile them into CommonJS modules. This is required because this library will be used through NodeJS which does not understand these new modules natively and we do not want to limit the developer in which syntax they prefer nor how they want to separate code.

The Rendering Process

SDK has its own reconciler for React components. It traverses through each element in the template structure and transforms it into a pure string. Additionally, prop children is also converted to a regular string and stored in the childrenContent prop, which is appended to each component. See example.

Restrictions:

  • React hooks is not allowed.
  • HTML tags at the moment is not supported.
  • React internal components like Fragments, Suspense etc. are skipped.

Requirements

To render the transpiled template SDK requires:

  • Node.js v18 and higher

The debug flag

When rendering you have the option of passing a debug flag which does not remove the transpiled files after the rendering process is done.

Example

import { Text, Indent, IndentationTypes, render } from '@asyncapi/generator-react-sdk';

class ClassComponent extends React.Component {
  constructor(props) { 
    super(props);
  }

  render() {
    // In `childrenContent` prop is stored `text wrapped by custom component\n\n`.
    // The content of the `children` prop is transformed to string and saved to the `childrenContent` prop.
    return this.props.childrenContent;
  }
}

function FunctionComponent() {
  return (
    <Indent size={3} type={IndentationTypes.TABS}>
      indented text
      <ClassComponent>
        <Text newLines={2}>
          text wrapped by custom component
        </Text>
      </ClassComponent>
    </Indent>
  );
}

// content will be `\t\t\tindented text text wrapped by custom component\n\n`
const content = render(<FunctionComponent />);

Resources

  • template-for-generator-templates template showcases features of the AsyncAPI Generator, including the React renderer. It shows how to write templates, reusable parts (components), what are the recommended patterns. It has simple and complex examples of using React.
  • markdown-template is written using React. It generates documentation into a Markdown file.

For more help join our Slack workspace.

Development

  1. Setup project by installing dependencies npm install
  2. Write code and tests.
  3. Make sure all tests pass npm test
  4. Make sure code is well formatted and secure npm run lint

Contributing

Read CONTRIBUTING guide.

generator-react-sdk's People

Contributors

asyncapi-bot avatar magicmatatjahu avatar derberg avatar jonaslagoni avatar mcturco avatar codingtenshi 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.