gas

package module
v0.0.0-...-454a2de Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2019 License: MIT Imports: 6 Imported by: 9

README

Gas - Components based frontend framework

GoDoc

Example: gascore.github.io

Logo

Structure
  1. gascore/gas - gas framework core
  2. gascore/gas/web - wasm/gopherjs backend
  3. gascore/gas-cli - projects manager for gas applications
  4. gascore/std - standard library for gas framework

Tasks and wiki

Documentation

Index

Constants

This section is empty.

Variables

CL alias for ToGetComponentList

NE alias for NewElement

Functions

func CallBeforeCreated

func CallBeforeCreated(i interface{}) error

CallBeforeCreated call component and it's childes BeforeCreated hook

func CallBeforeDestroy

func CallBeforeDestroy(i interface{}) error

CallBeforeDestroy call component and it's childes WillDestroy hook

func CallBeforeUpdate

func CallBeforeUpdate(p *Element) error

CallBeforeUpdate call BeforeUpdate hook

func CallMounted

func CallMounted(i interface{}) error

CallMounted call component and it's childes Mounted hook

func CallUpdated

func CallUpdated(p *Element) error

CallUpdated call Updated hook

func Changed

func Changed(newEl, oldEl interface{}) (bool, bool, error)

Changed return isChanged? and canGoDeeper?

func IsComponent

func IsComponent(c interface{}) bool

IsComponent return true if interface.(type) == *Component

func IsElement

func IsElement(c interface{}) bool

IsElement return true if interface.(type) == *Element

func IsString

func IsString(c interface{}) bool

IsString return true if interface is string

func RemoveStrings

func RemoveStrings(arr []interface{}) []interface{}

RemoveStrings remove all strings from []interface{}

func ToGetComponentList

func ToGetComponentList(childes ...interface{}) []interface{}

ToGetComponentList return array by many parameters, because it's pretty

func UnSpliceBody

func UnSpliceBody(body []interface{}) []interface{}

UnSpliceBody extract values fromm array to component childes

Types

type BackEnd

type BackEnd interface {
	ExecTasks([]*RenderTask)
	GetElement(*Element) interface{}
	ChildNodes(interface{}) []interface{}

	ConsoleLog(...interface{})
	ConsoleError(...interface{})
}

BackEnd interface for calling platform-specific code

func GetEmptyBackend

func GetEmptyBackend() BackEnd

GetEmptyBackend return empty BackEnd

type Bind

type Bind func() string

Bind dynamic component attribute

type C

type C = Component

C alias for Component

type Component

type Component struct {
	Root interface {
		Render() *Element
	}

	Element *Element // last-time render by root element from
	Hooks   Hooks

	RefsAllowed bool
	Refs        map[string]*Element

	NotPointer bool // by default component is pointer

	RC *RenderCore
}

Component logic node

func ElementToComponent

func ElementToComponent(el *Element) *Component

ElementToComponent create static component from element

func I2C

func I2C(a interface{}) *Component

I2C - convert interface{} to *Component

func (*Component) ConsoleError

func (c *Component) ConsoleError(a ...interface{})

ConsoleError call BackEnd.ConsoleError

func (*Component) ConsoleLog

func (c *Component) ConsoleLog(a ...interface{})

ConsoleLog call BackEnd.ConsoleLog

func (*Component) RenderElement

func (c *Component) RenderElement() *Element

RenderElement create element for elements tree

func (*Component) Update

func (component *Component) Update()

Update update component childes with error warning

func (*Component) UpdateWithError

func (component *Component) UpdateWithError() error

UpdateWithError update component childes

func (*Component) WarnError

func (c *Component) WarnError(err error)

WarnError log error

func (*Component) WarnIfNot

func (c *Component) WarnIfNot(ok bool)

WarnIfNot console error if !ok

type DynamicComponent

type DynamicComponent func(External) *Component

type DynamicElement

type DynamicElement func(External) *Element

type E

type E = Element

E alias for Element

func I2E

func I2E(a interface{}) *E

I2E - convert interface{} to *Element

type Effect

type Effect func() (func(), error)

Effect functional components effect

type Element

type Element struct {
	UUID      string
	IsPointer bool // by default element isn't pointer

	Tag      string
	Attrs    func() Map
	RAttrs   Map                // last rendered Attrs
	Handlers map[string]Handler // events handlers: onClick, onHover

	HTML  func() string
	RHTML string

	Childes, OldChildes []interface{}

	Parent  *Element // if element is root, parent is nil
	RefName string

	Component *Component // can be nil

	RC *RenderCore
}

Element stucture for basic strucutre nodes (html elements, etc)

func NewElement

func NewElement(el *Element, childes ...interface{}) *Element

NewElement create new element

func (*Element) BEElement

func (e *Element) BEElement() interface{}

BEElement return element in backend implementation

func (*Element) GetElementUnsafely

func (e *Element) GetElementUnsafely() interface{}

GetElementUnsafely return *dom.Element by component without warning

func (*Element) ParentComponent

func (e *Element) ParentComponent() *Element

ParentComponent return first component in element parents tree

func (*Element) ReCreate

func (e *Element) ReCreate()

ReCreate re create element

func (*Element) UpdateChildes

func (e *Element) UpdateChildes()

UpdateChildes update element childes

type EmptyRoot

type EmptyRoot struct {
	C       *Component
	Element *Element
}

EmptyRoot root for component only rendering one element

func (*EmptyRoot) Render

func (root *EmptyRoot) Render() *Element

type Event

type Event interface {
	Object
	Value() string
	ValueInt() int
	ValueBool() bool
}

Event wrapper for dom.Event

type External

type External struct {
	Body      []interface{}
	Slots     map[string]interface{}
	Templates map[string]Template
	Attrs     func() Map
}

External structure for passing values to external components

type F

F alias for FunctionalComponent

type FunctionalComponent

type FunctionalComponent struct {
	C *Component
	// contains filtered or unexported fields
}

FunctionalComponent wrapper for Component with react hooks (in gas maner)

func (*FunctionalComponent) Init

func (f *FunctionalComponent) Init(notPointer bool, renderer func() *E) *C

Init create *C from *F

func (*FunctionalComponent) Render

func (root *FunctionalComponent) Render() *Element

Render return functionalComponent childes

func (*FunctionalComponent) UseEffect

func (root *FunctionalComponent) UseEffect(effect Effect)

UseEffect add effect

func (*FunctionalComponent) UseState

func (root *FunctionalComponent) UseState(defaultVal interface{}) (func() interface{}, func(interface{}))

UseState create new state value

func (*FunctionalComponent) UseStateBool

func (root *FunctionalComponent) UseStateBool(defaultVal bool) (func() bool, func(bool))

func (*FunctionalComponent) UseStateFloat32

func (root *FunctionalComponent) UseStateFloat32(defaultVal float32) (func() float32, func(float32))

func (*FunctionalComponent) UseStateFloat64

func (root *FunctionalComponent) UseStateFloat64(defaultVal float64) (func() float64, func(float64))

func (*FunctionalComponent) UseStateInt

func (root *FunctionalComponent) UseStateInt(defaultVal int) (func() int, func(int))

func (*FunctionalComponent) UseStateInt16

func (root *FunctionalComponent) UseStateInt16(defaultVal int16) (func() int16, func(int16))

func (*FunctionalComponent) UseStateInt32

func (root *FunctionalComponent) UseStateInt32(defaultVal int32) (func() int32, func(int32))

func (*FunctionalComponent) UseStateInt64

func (root *FunctionalComponent) UseStateInt64(defaultVal int64) (func() int64, func(int64))

func (*FunctionalComponent) UseStateInt8

func (root *FunctionalComponent) UseStateInt8(defaultVal int8) (func() int8, func(int8))

func (*FunctionalComponent) UseStateString

func (root *FunctionalComponent) UseStateString(defaultVal string) (func() string, func(string))

func (*FunctionalComponent) UseStateUint

func (root *FunctionalComponent) UseStateUint(defaultVal uint) (func() uint, func(uint))

func (*FunctionalComponent) UseStateUint16

func (root *FunctionalComponent) UseStateUint16(defaultVal uint16) (func() uint16, func(uint16))

func (*FunctionalComponent) UseStateUint32

func (root *FunctionalComponent) UseStateUint32(defaultVal uint32) (func() uint32, func(uint32))

func (*FunctionalComponent) UseStateUint64

func (root *FunctionalComponent) UseStateUint64(defaultVal uint64) (func() uint64, func(uint64))

func (*FunctionalComponent) UseStateUint8

func (root *FunctionalComponent) UseStateUint8(defaultVal uint8) (func() uint8, func(uint8))

type G

type G = Gas

G alias for Gas

type Gas

type Gas struct {
	Component *Component
}

Gas - main application struct

func New

func New(c *Component, be BackEnd) *Gas

New create new gas application with custom backend

type HTMLDirective

type HTMLDirective struct {
	Render func() string

	Rendered string // here storing rendered html for Update functions
}

HTMLDirective struct for HTML Directive - storing render function and pre rendered render

type Handler

type Handler func(Event)

Handler function for triggering event

type Hook

type Hook func() error

Hook - lifecycle hook

type HookWithControl

type HookWithControl func() (rerender bool, err error)

HookWithControl - lifecycle hook. Return true for rerender component childes

type Hooks

type Hooks struct {
	BeforeCreated HookWithControl // When parent already rendered (appended to DOM), but component Element don't yet (you can rerender childes)
	Created       Hook            // When component has been created in golang only (Element isn't available)

	Mounted Hook // When component has been mounted (Element is available)

	BeforeDestroy Hook // Before component destroy (Element is available)

	BeforeUpdate Hook // When component child don't updated
	Updated      Hook // After component child was updated
}

Hooks component lifecycle hooks

type Map

type Map map[string]string

func DiffAttrs

func DiffAttrs(newA, oldA Map) Map

type Object

type Object interface {
	String() string
	Int() int
	Float() float64

	Get(string) Object
	Set(string, interface{})
	GetString(string) string
	GetBool(string) bool
	GetInt(string) int

	Call(string, ...interface{}) Object

	Raw() interface{}
}

Object wrapper for js.Value

type RenderCore

type RenderCore struct {
	BE BackEnd
	// contains filtered or unexported fields
}

RenderCore render station

func GetEmptyRenderCore

func GetEmptyRenderCore() *RenderCore

GetEmptyRenderCore return epmty render core

func (*RenderCore) Add

func (rc *RenderCore) Add(task *RenderTask)

Add push render tasks to render queue and trying to execute all queue

func (*RenderCore) Exec

func (rc *RenderCore) Exec()

Exec run all render nodes in render core

func (*RenderCore) GetAll

func (rc *RenderCore) GetAll() []*RenderTask

GetAll return render nodes from queue

func (*RenderCore) UpdateElementChildes

func (rc *RenderCore) UpdateElementChildes(_el interface{}, el *Element, new, old []interface{}, inReplaced bool) error

UpdateElementChildes compare new and old trees

type RenderTask

type RenderTask struct {
	ID int64

	Type RenderType

	Parent *Element

	New, Old                     interface{} // *Element, string, int, ...
	NodeParent, NodeNew, NodeOld interface{} // *dom.Element

	ReplaceCanGoDeeper bool
	InReplaced         bool
}

RenderTask node storing changes

type RenderType

type RenderType int

RenderType RenderTask type

const (
	// RReplace type for replace node
	RReplace RenderType = iota

	// RReplaceHooks type for run after replace hooks
	RReplaceHooks

	// RCreate type for create nodes
	RCreate

	// RFirstRender type for first gas render
	RFirstRender

	// RDelete type for delete node
	RDelete

	// RRecreate type for recreate node
	RRecreate
)

type Template

type Template func(...interface{}) []interface{}

Template function returning elements

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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