matthewmueller / joy

A delightful Go to Javascript compiler (ON HOLD)
https://mat.tm/joy
GNU General Public License v3.0
1.32k stars 35 forks source link

deep interfaces #36

Closed matthewmueller closed 6 years ago

matthewmueller commented 6 years ago

This doesn't quite work yet:

package main

// VNode interface
type VNode interface {
    String() string
}

// Component interface
type Component interface {
    Render() string
}

type vnode struct {
    c *Component
}

func (v *vnode) String() string {
    return "earth"
}

func newComponent(c Component) VNode {
    return &vnode{&c}
}

type index struct {
    location string
}

func (i *index) Render() string {
    return i.location
}

func newIndex(location string) VNode {
    return newComponent(&index{location})
}

func main() {
    c := newIndex("mars")
    println(c.String())
}