Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react: enhance JSX #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

lijianying10
Copy link
Contributor

In package react/jsx too many tags not implementation.

Since that, I have added a new function CreateElementFromJS after several days of usage. And it works well.

How to use this function

First install NPM dependance

yarn add babel-cli babel-preset-react --dev

Write JSX file and compile it

babel someComponent.jsx -o someComponentGen.js -w

Definitely babel will watch source code change and auto compile it into js.

Import someComponentGen.js to index.html

Usage in Go

Example: someComponent.jsx

function componentDetail(toolbar, ServiceName, Ports, Domain, Cluster, Namespace,
                         btn_Edit, btn_Delete, btn_NewVersion, versionCards) {
    return <div>
        {toolbar}
        <div className="mdl-grid component-detail">
            <div className="mdl-cell mdl-cell--5-col no-padding">
                <div className="mdl-grid no-padding">
                    <div className="mdl-cell mdl-cell--12-col service-border ui raised segment">
                        <div className="mdl-grid no-padding">
                            <div className="mdl-cell mdl-cell--10-col">
                                <div>{ServiceName}</div>
                            </div>
                            <div className="mdl-cell mdl-cell--2-col align-right">
                                <div>Ports:{Ports}</div>
                            </div>
                            <div className="mdl-cell mdl-cell--12-col">
                                <a href={Domain} target="_blank">{Domain}</a>
                            </div>
                            <div className="mdl-cell mdl-cell--8-col">
						<span className="mdl-chip">
							<span className="mdl-chip__text">Cluster: {Cluster}</span>
						</span>
                                <span className="mdl-chip">
							<span className="mdl-chip__text">Namespace: {Namespace}</span>
						</span>
                            </div>
                            <div className="mdl-cell mdl-cell--4-col align-right">
                                {btn_Edit}
                                {/*{btn_Delete}*/}
                                {btn_NewVersion}
                            </div>
                        </div>
                    </div>
                </div>
                {versionCards}
            </div>
        </div>
    </div>

}

Then in go

react.CreateElementFromJS(js.Global.Call("componentDetail",
		// Insert your Component
))

conclude

It's much more clear for manage components and convenience upgrade webpage.

@myitcv
Copy link
Owner

myitcv commented Sep 7, 2018

@lijianying10 I'm a little clear what the use case is here.

Not long ago we merged a change to improve the core React element generator, which also generates the JSX "half" too.

We will ultimately move to generating based on the HTML 5 spec, which will mean we get full coverage on elements and attributes

Does the current master make things better in your opinion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants