Help us shape the future of Go! Take the 2026 Go Developer Survey

functy

package module
v0.0.0-...-015f63f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2019 License: MIT Imports: 1 Imported by: 0

README

Hi Gophers! Unfortunately, I don't have the time to maintain this library right now, so I can't add any features. I'll gladly accept pull requests if you're interested. Also, if you'd like to maintaining the library longer term, I'm also happy to welcome you as a contributor. If you're interested in either submitting a PR or being a longer term maintainer, please let me know on the Gophers Slack. My username there is arschles.

functy

Often times, vecty code will have lots of nested function calls and the code gets hard to read and manage. This module has convenience functions for building up vecty elements in a functional pattern.

Below is an example adapted from the vecty example code for rendering Markdown:

import (
    "github.com/go-functional/functy"
    "github.com/gopherjs/vecty/elem"
    "github.com/gopherjs/vecty"
)

// PageView is our main page component.
type PageView struct {
    vecty.Core
    Input string
}

// Render implements the vecty.Component interface.
func (p *PageView) Render() vecty.ComponentOrHTML {
    body := functy.Wrap(elem.Body)
    div := functy.Wrap(elem.Div).
        Markup(vecty.Style("float", "right"))
    textArea := functy.Wrap(elem.TextArea).
        Markup(vecty.Style("font-family", "monospace")).
        Markup(vecty.Property("rows", 14)).
        Markup(vecty.Property("cols", 70)).
        Markup(event.Input(func(e *vecty.Event) {
            p.Input = e.Target.Get("value").Strting()
            vecty.Rerender(p)
        }))
        Markup(elem.TextArea).
        Child(vecty.Text(p.Input))
    return functy.Wrap(elem.Body).Child(div.Child(textArea))
}

Inspired by:

And built on the shoulders of vecty, of course!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Wrapper

type Wrapper struct {
	// contains filtered or unexported fields
}

Wrapper is the top level struct for any vecty element. Don't create one of these structs directly. Instead, call the Wrap function to bring elements from the vecty world into the functy world

func Peer

func Peer(parent Wrapper, children ...Wrapper) Wrapper

Peer returns a new Wrapper with children as first-level children of parent

func Wrap

func Wrap(fn func(...vecty.MarkupOrChild) *vecty.HTML) Wrapper

Wrap some standard vecty HTML so that you can manipulate it with functy builders. For example, here's how you'd build a <form>:

form := Wrap(elem.Form). // don't _call_ elem.Form() here!
	Markup(vecty.Class("sample-form")). // add class="sample-form"
	Child(elem.Input). // add an <input> element into this form
	Markup(vecty.Class("edit")). // add class="edit"
	Markup(prop.Value("edit something here!")). // value="edit something here!"
	Event(event.Input(inputCallback)) // call the (go) function called inputCallback()

func (Wrapper) Apply

func (w Wrapper) Apply() *vecty.HTML

Apply converts the wrapper into a vecty.HTML so you can use it in your "regularly scheduled" code

func (Wrapper) ChildFn

func (w Wrapper) ChildFn(fn func(...vecty.MarkupOrChild) *vecty.HTML) Wrapper

ChildFn returns a copy of w with the child inside of it

func (Wrapper) Markup

func (w Wrapper) Markup(appliers ...vecty.Applyer) Wrapper

Markup adds some markup to the vecty element in the wrapper

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL