Documentation ¶
Index ¶
- func RenderToDomId(c Component, domId string) error
- type Class
- type Component
- type Components
- type Props
- type This
- func (t *This) Children() Components
- func (t *This) ComponentDidMount()
- func (t *This) ComponentWillUnmount()
- func (t *This) Content() string
- func (t *This) ForceUpdate() error
- func (t *This) Props() Props
- func (t *This) Render() Component
- func (t *This) SetThis(this *js.Object) error
- func (t *This) Tag() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RenderToDomId ¶
Types ¶
type Class ¶
Class is a function that takes Props and Components, returning a new Component. It does not provide the actual implmentation of a Component, but rather it is a loose specification to easily create instances of components.
In other words, you should create a function for each of your components, with your desired component name for users of your component to cleanly create instances of it.
To go into rather absurd detail, lets look at some examples. In essence, a Class is similar to JSX. In JSX, we could use:
<div></div>
To create a div instance. In go-react, we would use:
Div()
Still not clear?, lets say we have a hand made html Component. It may look something like this:
type Div struct { props Props children []Component } func (c *Div) Render() []Component { return c.children } func (c *Div) Tag() string { return "div" } func (c *Div) Props() string { return nil } func (c *Div) Content() string { return "" }
If we had a whole series of html elements like this, and wanted to initialize them for actual use, it might look like this:
Div{props: nil, children: []Component{ Header{props: nil, children: []Component{ H1{props: Props{"className": "title"}, children: []Component{ Span{props: nil, []Component{react.Content("My Website!")}}, }, }, Ul{props: nil, children: []Component{}}, } }
Now lets compare this to what the JSX would look like:
<div> <header> <h1 className="title"> <span>My Website!</span> </h1> <ul></ul> </div>
The JSX presents a far more readable representation of the given components. To emulate that nice JSX, we can create functions that initialize our Go Components. Visually, it will look far closer to the JSX. Example:
Div(nil, Header(nil, H1(react.Props{"className": "title"}, Span(nil, react.Content("My Website!")), ), Ul(), ), )
Both of the Go examples create the same Components, they're just presented in a much cleaner way. By providing a function of type Class for your own Components, you can drastically improve the cleanliness of your component creations.
var ( Div Class = HtmlFactory("div") Span Class = HtmlFactory("span") P Class = HtmlFactory("p") Ol Class = HtmlFactory("ol") Ul Class = HtmlFactory("ul") Li Class = HtmlFactory("li") H1 Class = HtmlFactory("h1") H2 Class = HtmlFactory("h2") H3 Class = HtmlFactory("h3") H4 Class = HtmlFactory("h4") H5 Class = HtmlFactory("h5") H6 Class = HtmlFactory("h6") Button Class = HtmlFactory("button") Code Class = HtmlFactory("code") Pre Class = HtmlFactory("pre") Textarea Class = HtmlFactory("pre") Form Class = HtmlFactory("form") Em Class = HtmlFactory("em") Strong Class = HtmlFactory("strong") // TODO: Implement special common options into the (not)Class func. A Class = HtmlFactory("a") )
func HtmlFactory ¶
HtmlFactory is an easy func for creating plain Tag classes. This is used to create the entire base suite of Html Components in the react package.
type Component ¶
type Component interface { SetThis(*js.Object) error // See: https://facebook.github.io/react/docs/component-api.html#forceupdate ForceUpdate() error // See: https://facebook.github.io/react/docs/component-specs.html#mounting-componentdidmount ComponentDidMount() // See: https://facebook.github.io/react/docs/component-specs.html#unmounting-componentwillunmount ComponentWillUnmount() Render() Component Children() Components Content() string Props() Props Tag() string }
type Components ¶
type Components []Component
type This ¶
type This struct {
// contains filtered or unexported fields
}
func (*This) Children ¶
func (t *This) Children() Components
func (*This) ComponentDidMount ¶
func (t *This) ComponentDidMount()
func (*This) ComponentWillUnmount ¶
func (t *This) ComponentWillUnmount()
func (*This) ForceUpdate ¶
TODO: (Maybe) Add a callback to the js.Call, and block for it's return. Why maybe? Well, the blocking call may not be worth it. Especially if ForceUpdate ends up being how we render in go-react
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
_examples
|
|
components
This Go package is comparable to the following React JSX: var CommentList = React.createClass({ render: function() { return ( <div className="commentList"> Hello, world! I am a CommentList.
|
This Go package is comparable to the following React JSX: var CommentList = React.createClass({ render: function() { return ( <div className="commentList"> Hello, world! I am a CommentList. |
hello
This Go package is comparable to the following React JSX: React.render( <h1>Hello, world!</h1>, document.getElementById('example') );
|
This Go package is comparable to the following React JSX: React.render( <h1>Hello, world!</h1>, document.getElementById('example') ); |