fussy

package
v0.0.0-...-e26fe04 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2019 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package fussy implements code parsing and generation for fuss.

The code generation emits boilerplate code for converting regular types into streams and simple reactive functions into reactive components.

The parser parses reactive functions to figure out the information needed to generate the associated boilerplate. Similar functionality for streams is not yet implemented.

Parser

A component in FUSS requires four things: the function implementing the component, its dependencies laid out in a struct, the public signature for the function and a constructor which creates the component. The first three are expected to be done by the author while the last is auto-generated by fussy. The parser can scan through any package figuring out the missing constructors.

A sample component illustrating the three parts above would look like this:

type ComponentFunc = func(key interface{}, args...) results
func component(d *dependencies, args ...) results {
     ... d.dependency1(...) ...
}

type dependencies struct {
     dependency1 DependentComponentFunc
     ...
}

When fussy.ParseDir(..) is called on the above, it returns a component info which when used with fussy.Generate() will yield a constructor like so:

func NewComponent() (update ComponentFunc, close func() {
...
}

This implementation above, when used, will automatically ensure that subsequent calls to update will only rebuild the parts that changed. This is done by creating a dependencies struct which themselves use their corresponding constructors to create enough state to only repeat parts of the sub-computation as needed.

Generator

The generator returns a string representation of a Go file filling in streams and components. Streams allow fields and array elements to create new sub-streams.

TODO describe streams

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(info Info) string

Generate returns the source code generated from the provided info

Types

type ArgInfo

type ArgInfo struct {
	Name, Type       string
	IsState          bool
	ImplementsEquals bool
	ImplementsStream bool
	ImplementsClose  bool
}

ArgInfo holds func arg related info

type ComponentInfo

type ComponentInfo struct {
	Name, Type    string
	Ctor          string
	Args, Results []ArgInfo
	Variadic      bool
	Subs          []SubComponentInfo
}

ComponentInfo holds info related to a component

func (*ComponentInfo) ContextName

func (c *ComponentInfo) ContextName() string

ContextName returns the name of the context arg

func (*ComponentInfo) ContextType

func (c *ComponentInfo) ContextType() string

ContextType returns the name of the context arg

func (*ComponentInfo) Invoke

func (c *ComponentInfo) Invoke() string

Invoke builds the "invocation" line

func (*ComponentInfo) LastArg

func (c *ComponentInfo) LastArg() ArgInfo

LastArg returns the last arg

func (*ComponentInfo) LastPublicResults

func (c *ComponentInfo) LastPublicResults() string

LastPublicResults returns all the public results but prefixed with last

func (*ComponentInfo) NonContextArgsArray

func (c *ComponentInfo) NonContextArgsArray() []ArgInfo

NonContextArgsArray returns the list of non-context args, including state

func (*ComponentInfo) PublicArgs

func (c *ComponentInfo) PublicArgs() string

PublicArgs returns a list of all public args

func (*ComponentInfo) PublicArgsArray

func (c *ComponentInfo) PublicArgsArray() []ArgInfo

PublicArgsArray returns all non-state args

func (*ComponentInfo) PublicArgsArrayEquals

func (c *ComponentInfo) PublicArgsArrayEquals() []ArgInfo

PublicArgsArrayEquals returns all non-state args implementing Equals

func (*ComponentInfo) PublicArgsArrayOther

func (c *ComponentInfo) PublicArgsArrayOther() []ArgInfo

PublicArgsArrayOther returns all non-state args which don't implement equals

func (*ComponentInfo) PublicArgsDecl

func (c *ComponentInfo) PublicArgsDecl() string

PublicArgsDecl returns all public args and types

func (*ComponentInfo) PublicResultsArray

func (c *ComponentInfo) PublicResultsArray() []ArgInfo

PublicResultsArray returns the non-state resultss

func (*ComponentInfo) PublicResultsDecl

func (c *ComponentInfo) PublicResultsDecl() string

PublicResultsDecl returns all public return values and their types

func (*ComponentInfo) StreamStateArgs

func (c *ComponentInfo) StreamStateArgs() []ArgInfo

StreamStateArgs returns all state args that implement events

type Info

type Info struct {
	// Generator indicates the raw code which generates this
	Generator  string
	Package    string
	Imports    [][2]string
	Components []ComponentInfo
}

Info contains all the info needed to generate code

func ParseDir

func ParseDir(dir, pkg string, skipFiles []string) (*Info, error)

ParseDir parses the provided directory for the named package and returns the set of components associaated

type SubComponentInfo

type SubComponentInfo struct {
	LocalName string
	ComponentInfo
}

SubComponentInfo holds sub-component related info

Jump to

Keyboard shortcuts

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