Skip to content

Commit

Permalink
add vdom back in
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewmueller committed Dec 4, 2017
1 parent 0353a3e commit 064c3b2
Show file tree
Hide file tree
Showing 13 changed files with 712 additions and 100 deletions.
4 changes: 2 additions & 2 deletions internal/compiler/defs/vdom.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func maybeVDOMCompositLit(ctx *context, n *ast.CompositeLit) error {

isNode := false
for _, iface := range ifaces {
if iface.Path() == vdomPath && iface.Name() == "Component" {
if iface.Path() == vdomPath && iface.Name() == "Child" {
isNode = true
break
}
Expand Down Expand Up @@ -164,7 +164,7 @@ func maybeVDOMFuncDecl(ctx *context, n *ast.FuncDecl) error {

isComponent := false
for _, def := range defs {
if def.OriginalName() == "Component" && vdomPath == def.Path() {
if def.OriginalName() == "Child" && vdomPath == def.Path() {
isComponent = true
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/compiler/translator/vdom.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (tr *Translator) maybeVDOMLit(d def.Definition, n *ast.CompositeLit) (jsast

isNode := false
for _, iface := range ifaces {
if iface.Path() == vdomPath && iface.Name() == "Component" {
if iface.Path() == vdomPath && iface.Name() == "Child" {
isNode = true
break
}
Expand Down Expand Up @@ -182,7 +182,7 @@ func findComponentIndex(fn defs.Functioner) (int, error) {

switch t := def.(type) {
case defs.Interfacer:
if t.Path() == vdomPath && t.Name() == "Component" {
if t.Path() == vdomPath && t.Name() == "Child" {
return i, nil
}
case defs.Structer:
Expand All @@ -191,7 +191,7 @@ func findComponentIndex(fn defs.Functioner) (int, error) {
return -1, err
}
for _, imp := range imps {
if imp.Path() == vdomPath && imp.Name() == "Component" {
if imp.Path() == vdomPath && imp.Name() == "Child" {
return i, nil
}
}
Expand Down
162 changes: 79 additions & 83 deletions testdata/_49-jsx/expected.js.txt → testdata/49-jsx/expected.js.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
;
(function() {
var pkg = {};
pkg["github.com/matthewmueller/joy/testdata/49-jsx/preact/preact.js"] = (function() {
return (function () {
;(function() {
var pkg = {};
pkg["github.com/matthewmueller/joy/testdata/49-jsx/preact/preact.js"] = (function() {
return (function () {
'use strict'
function VNode() { }
function h(nodeName, attributes) {
Expand Down Expand Up @@ -609,82 +608,79 @@ return (function () {
options: options
}
})()
;
})();
pkg["github.com/matthewmueller/joy/runtime"] = (function() {
mapper.prototype.JSON = function() {
var m = this;
return m.obj;
};
function mapper (o) {
o = o || {};
this.obj = o.obj || {};
};
function Map () {
return new mapper({});
};
mapper.prototype.Set = function(key, value) {
var m = this;
m.obj[key] = value;
return m;
};
return {
Map: Map
};
})();
pkg["github.com/matthewmueller/joy/testdata/49-jsx/header"] = (function() {
function state (o) {
o = o || {};
this.count = o.count || 0;
};
Header.prototype.componentWillMount = function() {
var d = this;
d.state.count = 5;
};
function props (o) {
o = o || {};
this.title = o.title || "";
this.bats = o.bats || "";
this.children = o.children || [];
};
function Header (o) {
o = o || {};
this.Component = o.Component || new pkg["github.com/matthewmueller/joy/testdata/49-jsx/preact/preact.js"].Component();
for (var $k in this.Component || pkg["github.com/matthewmueller/joy/testdata/49-jsx/preact/preact.js"].Component.prototype) {
this[$k] = this[$k] || (this.Component || pkg["github.com/matthewmueller/joy/testdata/49-jsx/preact/preact.js"].Component.prototype)[$k]
};
this.props = o.props || new props();
this.state = o.state || new state();
};
Header.prototype.render = function() {
var d = this;
return pkg["github.com/matthewmueller/joy/testdata/49-jsx/preact/preact.js"].h('h3', pkg["github.com/matthewmueller/joy/runtime"].Map().Set('class', d.props.title).Set("count", d.state.count) ? pkg["github.com/matthewmueller/joy/runtime"].Map().Set('class', d.props.title).Set("count", d.state.count).JSON() : {}, [d.props.children]);
};
function New (title) {
var children = Array.prototype.slice.call(arguments, 1);
return pkg["github.com/matthewmueller/joy/testdata/49-jsx/preact/preact.js"].h(Header, new props({
title: title,
children: children
}));
};
return {
Header: Header,
New: New
};
})();
pkg["github.com/matthewmueller/joy/testdata/49-jsx"] = (function() {
var header = pkg["github.com/matthewmueller/joy/testdata/49-jsx/header"];
function main () {
;
var hdr = pkg["github.com/matthewmueller/joy/testdata/49-jsx/preact/preact.js"].h('h2', pkg["github.com/matthewmueller/joy/runtime"].Map().Set('class', "hi") ? pkg["github.com/matthewmueller/joy/runtime"].Map().Set('class', "hi").JSON() : {}, ["yo!", header.New.apply(null, ["lol"].concat("hi!"))]);
var w = window;
var document = w.document;
pkg["github.com/matthewmueller/joy/testdata/49-jsx/preact/preact.js"].render(hdr, document.body);
console.log(document.body.innerHTML);
};
return {
main: main
};
})();
return pkg["github.com/matthewmueller/joy/testdata/49-jsx"].main();

})();
pkg["github.com/matthewmueller/joy/internal/runtime"] = (function() {
mapper.prototype.JSON = function() {
var m = this;
return m.obj;
};
function mapper (o) {
o = o || {};
this.obj = o.obj || {}
};
function Map () {
return new mapper({});
};
mapper.prototype.Set = function(key, value) {
var m = this;
m.obj[key] = value;
return m;
};
return {
Map: Map
};
})();
pkg["github.com/matthewmueller/joy/testdata/49-jsx/header"] = (function() {
Header.prototype.componentWillMount = function() {
var d = this;
d.state.count = 5
};
function Header (o) {
o = o || {};
this.Component = o.Component || new pkg["github.com/matthewmueller/joy/testdata/49-jsx/preact/preact.js"].Component();
for (var $k in this.Component || pkg["github.com/matthewmueller/joy/testdata/49-jsx/preact/preact.js"].Component.prototype) {
this[$k] = this[$k] || (this.Component || pkg["github.com/matthewmueller/joy/testdata/49-jsx/preact/preact.js"].Component.prototype)[$k]
};
this.props = o.props || {
title: "",
bats: "",
children: []
};
this.state = o.state || {
count: 0
}
};
Header.prototype.render = function() {
var d = this;
return pkg["github.com/matthewmueller/joy/testdata/49-jsx/preact/preact.js"].h('h3', pkg["github.com/matthewmueller/joy/internal/runtime"].Map().Set('class', d.props.title).Set("count", d.state.count) ? pkg["github.com/matthewmueller/joy/internal/runtime"].Map().Set('class', d.props.title).Set("count", d.state.count).JSON() : {}, [d.props.children]);
};
function New (title) {
var children = Array.prototype.slice.call(arguments, 1);
return pkg["github.com/matthewmueller/joy/testdata/49-jsx/preact/preact.js"].h(Header, {
title: title,
bats: "",
children: children
});
};
return {
Header: Header,
New: New
};
})();
pkg["github.com/matthewmueller/joy/testdata/49-jsx"] = (function() {
var header = pkg["github.com/matthewmueller/joy/testdata/49-jsx/header"];
function main () {
;
var hdr = pkg["github.com/matthewmueller/joy/testdata/49-jsx/preact/preact.js"].h('h2', pkg["github.com/matthewmueller/joy/internal/runtime"].Map().Set('class', "hi") ? pkg["github.com/matthewmueller/joy/internal/runtime"].Map().Set('class', "hi").JSON() : {}, ["yo!", header.New.apply(null, ["lol"].concat("hi!"))]);
var w = window;
var document = w.document;
pkg["github.com/matthewmueller/joy/testdata/49-jsx/preact/preact.js"].render(hdr, document.body);
console.log(document.body.innerHTML)
};
return {
main: main
};
})();
return pkg["github.com/matthewmueller/joy/testdata/49-jsx"].main();
})()
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package header

import (
"github.com/matthewmueller/joy/vdom"
"github.com/matthewmueller/joy/vdom/h/h3"
"github.com/matthewmueller/joy/vdom/h3"
)

// Header struct
Expand Down
File renamed without changes.
7 changes: 4 additions & 3 deletions testdata/_49-jsx/input.go → testdata/49-jsx/input.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package main

import (
"github.com/matthewmueller/joy/dom/htmlbodyelement"
"github.com/matthewmueller/joy/dom/window"
"github.com/matthewmueller/joy/testdata/49-jsx/header"
"github.com/matthewmueller/joy/testdata/49-jsx/preact"
"github.com/matthewmueller/joy/testdata/49-jsx/window"
"github.com/matthewmueller/joy/vdom"
"github.com/matthewmueller/joy/vdom/h/h2"
"github.com/matthewmueller/joy/vdom/h2"
)

func main() {
Expand All @@ -18,6 +19,6 @@ func main() {

w := window.New()
document := w.Document()
preact.Render(hdr, document.Body())
preact.Render(hdr, document.Body().(*htmlbodyelement.HTMLBodyElement))
println(document.Body().InnerHTML())
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package preact

import (
"github.com/matthewmueller/joy/dom/window"
"github.com/matthewmueller/joy/macro"
"github.com/matthewmueller/joy/testdata/49-jsx/window"
"github.com/matthewmueller/joy/vdom"
)

Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 064c3b2

Please sign in to comment.