views

package
v0.0.0-...-a33cf17 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2016 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package views contain the state machine and view system used by Haiku components

Index

Constants

This section is empty.

Variables

View Source
var ErrBadSelector = errors.New("Selector returned nil")

ErrBadSelector is used to indicate if the selector returned no result

View Source
var ErrExists = errors.New("Tag already assigned")

ErrExists is returned when the ViewLists has the tag already asigned

View Source
var ErrInvalidStateAddr = errors.New("State Not Found")

ErrInvalidStateAddr is returned when a wrong length or format state address is found

View Source
var ErrNotSupported = errors.New("Feature not supported")

ErrNotSupported is returned when a feature requested is not supported by the environment

View Source
var ErrStateNotFound = errors.New("State Not Found")

ErrStateNotFound is returned when the state address is inaccurate and a state was not found in the path

Functions

func AddNodeIfNone

func AddNodeIfNone(dest, src *js.Object)

AddNodeIfNone uses the dom.Node.IsEqualNode method to check if not already exist and if so swap them else just add NOTE: bad way of doing it use it as last option

func AddNodeIfNoneInList

func AddNodeIfNoneInList(dest *js.Object, against []*js.Object, with *js.Object) bool

AddNodeIfNoneInList checks a node in a node list if it finds an equal it replaces only else does nothing

func BrowserSupportsPushState

func BrowserSupportsPushState() bool

BrowserSupportsPushState checks if browser supports pushState

func CreateFragment

func CreateFragment(html string) *js.Object

CreateFragment returns a DocumentFragment with the given html dom

func GetLocation

func GetLocation() (string, string)

GetLocation returns the path and hash of the browsers location api else panics if not in a browser

func HashSequencer

func HashSequencer(path, hash string) string

HashSequencer provides a PathSequencer that returns the hash part of a url, as the path sequence.

func Patch

func Patch(fragment, live *js.Object, onlyReplace bool)

Patch takes a dom string and creates a documentfragment from it and patches a existing dom element that is supplied. This algorithim only ever goes one-level deep, its not performant WARNING: this method is specifically geared to dealing with the haiku.Tree dom generation

func PushDOMState

func PushDOMState(path string)

PushDOMState adds a new state the dom push history

func SetDOMHash

func SetDOMHash(hash string)

SetDOMHash sets the dom location hash

func URLPathSequencer

func URLPathSequencer(path, hash string) string

URLPathSequencer provides a PathSequencer that returns the path part of a url, as the path sequence.

Types

type Behaviour

type Behaviour interface {
	Hide()
	Show()
}

Behaviour provides a state changers for haiku.

type HideView

type HideView struct{}

HideView provides a ViewStates for Views inactive state

func (*HideView) Render

func (v *HideView) Render(m trees.Markup)

Render marks the given markup as display:none

type HistoryProvider

type HistoryProvider struct {
	*PathObserver
}

HistoryProvider wraps the PathObserver with methods that allow easy control of client location

func History

func History(ps PathSequencer) *HistoryProvider

History returns a new PathObserver and depending on browser support will either use the popState or HashChange

func (*HistoryProvider) Go

func (h *HistoryProvider) Go(path string)

Go changes the path of the current browser location depending on wether its underline observe is hashed based or pushState based,it will use SetDOMHash or PushDOMState appropriately

type MarkupRenderer

type MarkupRenderer interface {
	Render(...string) trees.Markup
	RenderHTML(...string) template.HTML
}

MarkupRenderer provides a interface for a types capable of rendering dom markup.

type Pages

type Pages struct {
	*StateEngine
	*HistoryProvider
}

Pages provides the concrete provider for managing a whole website or View you dont need two,just one is enough to manage the total web view of your app / site It ties directly into the page hash or popstate location to provide consistent updates

func NewPage

func NewPage(p *HistoryProvider) *Pages

NewPage returns the new state engine powered page

func Page

func Page(ps PathSequencer) *Pages

Page returns the new state engine powered page

func (*Pages) AddView

func (p *Pages) AddView(addr string, v Views)

AddView adds a view to the page

func (*Pages) Address

func (p *Pages) Address() (string, string)

Address returns the current path and hash of the location api

func (*Pages) Mount

func (p *Pages) Mount(selector, addr string, v Views) error

Mount adds a component into the page for handling/managing of visiblity and gets the dom referenced by the selector using QuerySelector and returns an error if selector gave no result

type PathObserver

type PathObserver struct {
	pub.Publisher
	// contains filtered or unexported fields
}

PathObserver represent any continouse changing route path by the browser

func HashChangePath

func HashChangePath(ps PathSequencer) *PathObserver

HashChangePath returns a path observer path changes

func Path

func Path(ps PathSequencer) *PathObserver

Path returns a new PathObserver instance

func PopStatePath

func PopStatePath(ps PathSequencer) (*PathObserver, error)

PopStatePath returns a path observer path changes

func (*PathObserver) Follow

func (p *PathObserver) Follow(path, hash string)

Follow creates a Pathspec from the hash and path and sends it

func (*PathObserver) FollowSpec

func (p *PathObserver) FollowSpec(ps PathSpec)

FollowSpec just passes down the Pathspec

func (*PathObserver) NotifyPage

func (p *PathObserver) NotifyPage(pg *Pages)

NotifyPage is used to notify a page of

func (*PathObserver) NotifyPartialPage

func (p *PathObserver) NotifyPartialPage(pg *Pages)

NotifyPartialPage is used to notify a Page using the page engine's Partial() activator

type PathSequencer

type PathSequencer func(path string, hash string) string

PathSequencer provides a function to convert either the path/hash into a dot seperated sequence string for use with States.

type PathSpec

type PathSpec struct {
	Hash     string
	Path     string
	Sequence string
}

PathSpec represent the current path and hash values

func (*PathSpec) String

func (p *PathSpec) String() string

String returns the hash and path

type ReactiveRenderable

type ReactiveRenderable interface {
	pub.Publisher
	Renderable
}

ReactiveRenderable provides a interface for a reactive renderable type.

type Renderable

type Renderable interface {
	Render(...string) trees.Markup
}

Renderable provides a interface for a renderable type.

type SequenceMeta

type SequenceMeta struct {
	Tag   string   // Name of the root tag.
	UID   string   // Custom UID of the root dom tag.
	ID    string   // Id of the root tag.
	Class []string // Class list of the root tag.
}

SequenceMeta provides a configuration object for SequenceRenderer.

type SequenceRenderer

type SequenceRenderer struct {
	pub.Publisher
	*SequenceMeta
	// contains filtered or unexported fields
}

SequenceRenderer provides a rendering lists of Renderables to be rendered in their added sequence/order. SequenceRenderer embedds pub.Publisher and will automatically bind with any ReactiveRenderable being added if its `Bind` is set to true.

func Sequence

func Sequence(meta SequenceMeta, r ...Renderable) *SequenceRenderer

Sequence returns a new sequence renderer instance.

func (*SequenceRenderer) Add

func (s *SequenceRenderer) Add(r ...Renderable)

Add adds new renders into the publisher lists.

func (*SequenceRenderer) Render

func (s *SequenceRenderer) Render(m ...string) trees.Markup

Render renders the giving giving lists of views.

type ShowView

type ShowView struct{}

ShowView provides a ViewStates for Views active state

func (*ShowView) Render

func (v *ShowView) Render(m trees.Markup)

Render marks the given markup with a display: block

type State

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

State represents a single state of with a specific tag and address where the address is a single piece 'home' item in the '.home.files' style state address

func NewState

func NewState() *State

NewState builds a new state with a tag and single address point .eg home or files ..etc

func (*State) Activate

func (s *State) Activate()

Activate activates the state

func (*State) Active

func (s *State) Active() bool

Active returns true/false if this state is active

func (*State) Deactivate

func (s *State) Deactivate()

Deactivate deactivates the state

func (*State) Engine

func (s *State) Engine() *StateEngine

Engine returns the internal nested StateEngine

func (*State) OverrideValidator

func (s *State) OverrideValidator(so StateValidator) States

OverrideValidator assigns an validator to perform custom matching of the state

func (*State) UseActivator

func (s *State) UseActivator(so StateResponse) States

UseActivator assigns the state a new active respone handler

func (*State) UseDeactivator

func (s *State) UseDeactivator(so StateResponse) States

UseDeactivator assigns the state a new deactivate respone handler

type StateEngine

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

StateEngine represents the engine that handles the state machine based operations for state-address based states

func BuildStateEngine

func BuildStateEngine(s States) *StateEngine

BuildStateEngine returns a new StateEngine instance set with a particular state as its owner

func NewStateEngine

func NewStateEngine() *StateEngine

NewStateEngine returns a new engine with a default empty state

func (*StateEngine) AddState

func (se *StateEngine) AddState(addr string) States

AddState adds a new state into the engine with the tag used to identify the state, if the address is a empty string then the address recieves the tag as its value, remember the address is a single address point .eg home or files and not the length of the extend address eg .root.home.files

func (*StateEngine) All

func (se *StateEngine) All(addr string) error

All renders the partial of the last state of the state address

func (*StateEngine) DeactivateAll

func (se *StateEngine) DeactivateAll()

DeactivateAll deactivates all states connected to this engine

func (*StateEngine) Partial

func (se *StateEngine) Partial(addr string) error

Partial renders the partial of the last state of the state address

func (*StateEngine) ShallowState

func (se *StateEngine) ShallowState() States

ShallowState returns the current state of the engine and not the final state i.e with a state address of '.home.files' from its root, it will return State(:home) object

func (*StateEngine) State

func (se *StateEngine) State() States

State returns the current last state of the engine with respect to any nested state that is with the state address of '.home.files', it will return State(:files) object

func (*StateEngine) UseState

func (se *StateEngine) UseState(addr string, s States) States

UseState adds a state into the StateEngine with a specific tag, the state address point is still used in matching against it

type StateResponse

type StateResponse func()

StateResponse defines the function type used by state in response to a state call

type StateValidator

type StateValidator func(string, string) bool

StateValidator defines a function type used in the state validator process

type States

type States interface {
	Active() bool
	// Tag() string
	Engine() *StateEngine
	Activate()
	Deactivate()
	UseActivator(StateResponse) States
	UseDeactivator(StateResponse) States
	OverrideValidator(StateValidator) States
	// contains filtered or unexported methods
}

States represent the interface defining a state type

type TemplateRenderable

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

TemplateRenderable defines a basic example of a Renderable

func NewTemplateRenderable

func NewTemplateRenderable(content string) (*TemplateRenderable, error)

NewTemplateRenderable returns a new Renderable

func (*TemplateRenderable) Execute

func (t *TemplateRenderable) Execute(v interface{}) error

Execute effects the inner template with the supplied data

func (*TemplateRenderable) Render

func (t *TemplateRenderable) Render(_ ...string) string

Render renders out the internal cache

func (*TemplateRenderable) RenderHTML

func (t *TemplateRenderable) RenderHTML(_ ...string) template.HTML

RenderHTML renders the output from .Render() as safe html unescaped

func (*TemplateRenderable) String

func (t *TemplateRenderable) String() string

String calls the render function

type View

type View struct {
	States
	pub.Publisher
	HideState ViewStates
	ShowState ViewStates
	// contains filtered or unexported fields
}

View represent a basic Haiku view

func MakeView

func MakeView(uid string, writer trees.MarkupWriter, vw Renderable) (vm *View)

MakeView returns a Components style

func NewScopedView

func NewScopedView(uid string, view Renderable) *View

NewScopedView returns a View instance with a custom UID. These allows managing effective transisitions from rendering on the backends to rendering on the frontend. The uid provides a unchanging identification of the server-rendered dom node the view is concerned about and it loads off that dom node on the client side to ensure correct transition.

func NewView

func NewView(view Renderable) *View

NewView returns a View instance. The view is giving a empty uid string, which it will generate itself. Use NewScopedView for more control especially when rendering from server.

func SequenceView

func SequenceView(meta SequenceMeta, rs ...Renderable) *View

SequenceView returns a new View instance rendered through a sequence renderer.

func (*View) BindView

func (v *View) BindView(vs Views)

BindView binds the given views together,were the view provided as argument will notify this view of change and to act according

func (*View) Events

func (v *View) Events() base.EventManagers

Events returns the views events manager

func (*View) Hide

func (v *View) Hide()

Hide deactivates the view

func (*View) History

func (v *View) History() (*HistoryProvider, error)

History returns the views current history provider.

func (*View) Mount

func (v *View) Mount(dom *js.Object)

Mount is to be called in the browser to loadup this view with a dom

func (*View) Render

func (v *View) Render(m ...string) trees.Markup

Render renders the generated markup for this view

func (*View) RenderHTML

func (v *View) RenderHTML(m ...string) template.HTML

RenderHTML renders out the views markup as a string wrapped with template.HTML

func (*View) Show

func (v *View) Show()

Show activates the view to generate a visible markup

func (*View) UseHistory

func (v *View) UseHistory(hs *HistoryProvider)

UseHistory sets the views HistoryProvider to effect navigation change.

type ViewList

type ViewList []Views

ViewList represent a list of Views elements

type ViewLists

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

ViewLists is a race-free struct providing a map for storing and retrieving Views which is used by *View

func NewViewLists

func NewViewLists() *ViewLists

NewViewLists returns a new instance of ViewLists

func (*ViewLists) Add

func (vm *ViewLists) Add(tag string, v Views) error

Add adds a Views to the view lists

func (*ViewLists) Get

func (vm *ViewLists) Get(tag string) Views

Get returns the Views with the giving tag if found else nil

func (*ViewLists) Has

func (vm *ViewLists) Has(tag string) bool

Has returns true/false if the tag has a Views

func (*ViewLists) Remove

func (vm *ViewLists) Remove(tag string) Views

Remove removes the Views if the given tag exists

func (*ViewLists) Views

func (vm *ViewLists) Views() ViewList

Views returns the slice within the viewlists

type ViewMap

type ViewMap map[string]int

ViewMap represent a set of Views element tagged by a string key

type ViewStates

type ViewStates interface {
	Render(trees.Markup)
}

ViewStates defines the two possible behavioral state of a view's markup

type Views

type Views interface {
	pub.Publisher
	States
	Behaviour
	MarkupRenderer

	Events() base.EventManagers
	Mount(*js.Object)
	BindView(Views)
	UseHistory(*HistoryProvider)
	History() (*HistoryProvider, error)
}

Views define a Haiku Component

Jump to

Keyboard shortcuts

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