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

Commit 4242302

Browse files
authored
Merge pull request #79 from myitcv/tidy_up
Tidy up package
2 parents fde816e + 1d5ff6f commit 4242302

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+248
-326
lines changed

a.go renamed to a_elem.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type AElem struct {
88
Element
99
}
1010

11-
// _APropsDef defines the properties for the <a> element
11+
// _AProps defines the properties for the <a> element
1212
type _AProps struct {
1313
*BasicHTMLElement
1414

@@ -28,13 +28,7 @@ func A(props *AProps, children ...Element) *AElem {
2828
props.assign(rProps)
2929
}
3030

31-
args := []interface{}{"a", rProps}
32-
33-
for _, v := range children {
34-
args = append(args, elementToReactObj(v))
31+
return &AElem{
32+
Element: createElement("a", rProps, children...),
3533
}
36-
37-
underlying := react.Call("createElement", args...)
38-
39-
return &AElem{Element: elementHolder{elem: underlying}}
4034
}

br.go

Lines changed: 0 additions & 30 deletions
This file was deleted.

br_elem.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) 2016 Paul Jolly <paul@myitcv.org.uk>, all rights reserved.
2+
// Use of this document is governed by a license found in the LICENSE document.
3+
4+
package react
5+
6+
// BrElem is the React element definition corresponding to the HTML <br> element
7+
type BrElem struct {
8+
Element
9+
}
10+
11+
// _BrProps defines the properties for the <br> element
12+
type _BrProps struct {
13+
*BasicHTMLElement
14+
}
15+
16+
// Br creates a new instance of a <br> element with the provided props
17+
func Br(props *BrProps) *BrElem {
18+
19+
rProps := &_BrProps{
20+
BasicHTMLElement: newBasicHTMLElement(),
21+
}
22+
23+
if props != nil {
24+
props.assign(rProps)
25+
}
26+
27+
return &BrElem{
28+
Element: createElement("br", rProps),
29+
}
30+
}

button.go renamed to button_elem.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,7 @@ func Button(props *ButtonProps, children ...Element) *ButtonElem {
2727
props.assign(rProps)
2828
}
2929

30-
args := []interface{}{"button", rProps}
31-
32-
for _, v := range children {
33-
args = append(args, elementToReactObj(v))
30+
return &ButtonElem{
31+
Element: createElement("button", rProps, children...),
3432
}
35-
36-
underlying := react.Call("createElement", args...)
37-
38-
return &ButtonElem{Element: elementHolder{elem: underlying}}
3933
}

cmd/reactGen/comp_gen.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ type {{.Name}}Elem struct {
212212
react.Element
213213
}
214214
215-
func ({{.Recv}} {{.Name}}Def) ShouldComponentUpdateIntf(nextProps, prevState, nextState interface{}) bool {
215+
func ({{.Recv}} {{.Name}}Def) ShouldComponentUpdateIntf(nextProps react.Props, prevState, nextState react.State) bool {
216216
res := false
217217
218218
{{if .HasProps -}}
@@ -271,7 +271,7 @@ func ({{.Recv}} {{.Name}}Def) GetInitialStateIntf() react.State {
271271
{{end -}}
272272
}
273273
274-
func ({{.Recv}} {{.Name}}State) EqualsIntf(val interface{}) bool {
274+
func ({{.Recv}} {{.Name}}State) EqualsIntf(val react.State) bool {
275275
{{if .StateHasEquals -}}
276276
return {{.Recv}}.Equals(val.({{.Name}}State))
277277
{{else -}}
@@ -282,6 +282,10 @@ func ({{.Recv}} {{.Name}}State) EqualsIntf(val interface{}) bool {
282282
283283
284284
{{if .HasProps}}
285+
// IsProps is an auto-generated definition so that {{.Name}}Props implements
286+
// the myitcv.io/react.Props interface.
287+
func ({{.Recv}} {{.Name}}Props) IsProps() {}
288+
285289
// Props is an auto-generated proxy to the current props of {{.Name}}
286290
func ({{.Recv}} {{.Name}}Def) Props() {{.Name}}Props {
287291
uprops := {{.Recv}}.ComponentDef.Props()
@@ -297,15 +301,15 @@ func ({{.Recv}} {{.Name}}Def) ComponentWillReceivePropsIntf(val interface{}) {
297301
}
298302
{{end}}
299303
300-
func ({{.Recv}} {{.Name}}Props) EqualsIntf(val interface{}) bool {
304+
func ({{.Recv}} {{.Name}}Props) EqualsIntf(val react.Props) bool {
301305
{{if .PropsHasEquals -}}
302306
return {{.Recv}}.Equals(val.({{.Name}}Props))
303307
{{else -}}
304308
return {{.Recv}} == val.({{.Name}}Props)
305309
{{end -}}
306310
}
307311
308-
var _ react.Equals = {{.Name}}Props{}
312+
var _ react.Props = {{.Name}}Props{}
309313
{{end}}
310314
`, cg)
311315

cmd/reactGen/props_gen.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ type propsGen struct {
2323
}
2424

2525
func (g *gen) genProps(defName string, t typeFile) {
26-
2726
name := strings.TrimPrefix(defName, propsTypeTmplPrefix)
2827

2928
r, _ := utf8.DecodeRuneInString(name)

code.go renamed to code_elem.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,7 @@ func Code(props *CodeProps, children ...Element) *CodeElem {
2424
props.assign(rProps)
2525
}
2626

27-
args := []interface{}{"code", rProps}
28-
29-
for _, v := range children {
30-
args = append(args, elementToReactObj(v))
27+
return &CodeElem{
28+
Element: createElement("code", rProps, children...),
3129
}
32-
33-
underlying := react.Call("createElement", args...)
34-
35-
return &CodeElem{Element: elementHolder{elem: underlying}}
3630
}

components/imm/gen_Select_reactGen.go

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

core.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ func newBasicHTMLElement() *BasicHTMLElement {
4343
}
4444
}
4545

46-
// TODO complete the definition
4746
type SyntheticEvent struct {
4847
o *js.Object
4948

div.go renamed to div_elem.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,7 @@ func Div(props *DivProps, children ...Element) *DivElem {
2424
props.assign(rProps)
2525
}
2626

27-
args := []interface{}{"div", rProps}
28-
29-
for _, v := range children {
30-
args = append(args, elementToReactObj(v))
27+
return &DivElem{
28+
Element: createElement("div", rProps, children...),
3129
}
32-
33-
underlying := react.Call("createElement", args...)
34-
35-
return &DivElem{Element: elementHolder{elem: underlying}}
3630
}

0 commit comments

Comments
 (0)