Skip to content
This repository has been archived by the owner on Aug 27, 2018. It is now read-only.

First cut of JSX-like support #65

Merged
merged 1 commit into from
May 2, 2017
Merged

First cut of JSX-like support #65

merged 1 commit into from
May 2, 2017

Conversation

myitcv
Copy link
Owner

@myitcv myitcv commented May 2, 2017

A runtime stop-gap solution for JSX-like support (will ultimately be replaced with a proper compile-time solution), per #64.

Also includes a first-cut of reactVet to catch misuse of the new myitcv.io/react/jsx package.

Allows things like:

func (a *MyCompDef) Render() r.Element {
	return r.Div(nil,
		jsx.HTML(`
		<h1>Hello world</h1>

		<p>This is my first GopherJS React App</p>
		`)...,
	)
}

or via Markdown:

func (a *MyCompDef) Render() r.Element {
	return r.Div(nil,
		jsx.Markdown(`
# Hello World

This is my first GopherJS React App
		`)...,
	)
}

Godocs:

package jsx
    import "myitcv.io/react/jsx"


FUNCTIONS

func HTML(s string) []r.Element
    HTML is a runtime JSX-like parser. It parses the supplied HTML string
    into myitcv.io/react element values. It exists as a stop-gap runtime
    solution to full JSX-like support within the GopherJS compiler. It
    should only be used where the argument is a compile-time constant string
    (TODO enforce this within reactVet). HTML will panic in case s cannot be
    parsed as a valid HTML fragment

func HTMLElem(s string) r.Element
    HTMLElem is a convenience wrapper around HTML where only a single root
    element is expected. HTMLElem will panic if more than one HTML element
    results

func Markdown(s string) []r.Element
    Markdown is a runtime JSX-like parser for markdown. It parses the
    supplied markdown string into an HTML string and then hands off to the
    HTML function. Like the HTML function, it exists as a stop-gap runtime
    solution to full JSX-like support within the GopherJS compiler. It
    should only be used where the argument is a compile-time constant string
    (TODO enforce this within reactVet). Markdown will panic in case the
    markdown string s results in an invalid HTML string

@myitcv myitcv force-pushed the first_cut_jsx branch 5 times, most recently from dce30b5 to 43a7f24 Compare May 2, 2017 17:15
@myitcv myitcv changed the title [WIP] First cut of JSX-like support First cut of JSX-like support May 2, 2017
@myitcv myitcv merged commit 890c91f into master May 2, 2017
@myitcv myitcv deleted the first_cut_jsx branch May 2, 2017 17:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant