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

Commit 6532e68

Browse files
committed
Automatically generate buildXElem functions to save boilerplate
1 parent 2b435e4 commit 6532e68

37 files changed

+132
-18
lines changed

cmd/reactGen/comp_gen.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@ func build{{.Name}}(cd react.ComponentDef) react.Component {
236236
return {{.Name}}Def{ComponentDef: cd}
237237
}
238238
239+
func build{{.Name}}Elem({{if .HasProps}}props {{.Name}}Props,{{end}} children ...react.Element) *{{.Name}}Elem {
240+
return &{{.Name}}Elem{
241+
Element: react.CreateElement(build{{.Name}}, {{if .HasProps}}props{{else}}nil{{end}}),
242+
}
243+
}
244+
239245
{{if .HasState}}
240246
// SetState is an auto-generated proxy proxy to update the state for the
241247
// {{.Name}} component. SetState does not immediately mutate {{.Recv}}.State()

cmd/reactGen/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ type AppDef struct {
8484
}
8585
8686
func App() *AppElem {
87-
return &AppElem{Element: r.CreateElement(buildApp, nil)}
87+
return buildAppElem()
8888
}
8989
9090
func (a AppDef) Render() r.Element {

components/imm/gen_Select_reactGen.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/imm/select.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type _Imm_entriesKeysSelect []entryKey
6161
// Select creates a new instance of the SelectDef component with the provided props
6262
//
6363
func Select(props SelectProps) *SelectElem {
64-
return &SelectElem{Element: r.CreateElement(buildSelect, props)}
64+
return buildSelectElem(props)
6565
}
6666

6767
func (p SelectDef) ComponentWillMount() {

examples/blog/2017_04_16/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type AppDef struct {
1111
}
1212

1313
func App() *AppElem {
14-
return &AppElem{Element: r.CreateElement(buildApp, nil)}
14+
return buildAppElem()
1515
}
1616

1717
func (a AppDef) Render() r.Element {

examples/blog/2017_04_16/foo_bar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type FooBarState struct {
4141
//
4242
func FooBar(p FooBarProps) *FooBarElem {
4343
// every component constructor must call this function
44-
return &FooBarElem{Element: r.CreateElement(buildFooBar, p)}
44+
return buildFooBarElem(p)
4545
}
4646

4747
// Render is a required method on all React components. Notice that the method

examples/blog/2017_04_16/gen_App_reactGen.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/blog/2017_04_16/gen_FooBar_reactGen.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/examples.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const (
3131

3232
// Examples creates instances of the Examples component
3333
func Examples() *ExamplesElem {
34-
return &ExamplesElem{Element: r.CreateElement(buildExamples, nil)}
34+
return buildExamplesElem()
3535
}
3636

3737
type (

examples/gen_Examples_reactGen.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)