Documentation ¶
Overview ¶
Package views contain the state machine and view system used by Haiku components
Index ¶
- Variables
- func AddNodeIfNone(dest, src *js.Object)
- func AddNodeIfNoneInList(dest *js.Object, against []*js.Object, with *js.Object) bool
- func BrowserSupportsPushState() bool
- func CreateFragment(html string) *js.Object
- func GetLocation() (string, string)
- func HashSequencer(path, hash string) string
- func Patch(fragment, live *js.Object, onlyReplace bool)
- func PushDOMState(path string)
- func SetDOMHash(hash string)
- func URLPathSequencer(path, hash string) string
- type Behaviour
- type HideView
- type HistoryProvider
- type MarkupRenderer
- type Pages
- type PathObserver
- type PathSequencer
- type PathSpec
- type ReactiveRenderable
- type Renderable
- type SequenceMeta
- type SequenceRenderer
- type ShowView
- type State
- type StateEngine
- func (se *StateEngine) AddState(addr string) States
- func (se *StateEngine) All(addr string) error
- func (se *StateEngine) DeactivateAll()
- func (se *StateEngine) Partial(addr string) error
- func (se *StateEngine) ShallowState() States
- func (se *StateEngine) State() States
- func (se *StateEngine) UseState(addr string, s States) States
- type StateResponse
- type StateValidator
- type States
- type TemplateRenderable
- type View
- func (v *View) BindView(vs Views)
- func (v *View) Events() base.EventManagers
- func (v *View) Hide()
- func (v *View) History() (*HistoryProvider, error)
- func (v *View) Mount(dom *js.Object)
- func (v *View) Render(m ...string) trees.Markup
- func (v *View) RenderHTML(m ...string) template.HTML
- func (v *View) Show()
- func (v *View) UseHistory(hs *HistoryProvider)
- type ViewList
- type ViewLists
- type ViewMap
- type ViewStates
- type Views
Constants ¶
This section is empty.
Variables ¶
var ErrBadSelector = errors.New("Selector returned nil")
ErrBadSelector is used to indicate if the selector returned no result
var ErrExists = errors.New("Tag already assigned")
ErrExists is returned when the ViewLists has the tag already asigned
var ErrInvalidStateAddr = errors.New("State Not Found")
ErrInvalidStateAddr is returned when a wrong length or format state address is found
var ErrNotSupported = errors.New("Feature not supported")
ErrNotSupported is returned when a feature requested is not supported by the environment
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 ¶
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 ¶
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 ¶
CreateFragment returns a DocumentFragment with the given html dom
func GetLocation ¶
GetLocation returns the path and hash of the browsers location api else panics if not in a browser
func HashSequencer ¶
HashSequencer provides a PathSequencer that returns the hash part of a url, as the path sequence.
func Patch ¶
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 URLPathSequencer ¶
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 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
type PathObserver ¶
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 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 ¶
PathSequencer provides a function to convert either the path/hash into a dot seperated sequence string for use with States.
type ReactiveRenderable ¶
type ReactiveRenderable interface { pub.Publisher Renderable }
ReactiveRenderable provides a interface for a reactive renderable type.
type Renderable ¶
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.
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) 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
type StateResponse ¶
type StateResponse func()
StateResponse defines the function type used by state in response to a state call
type StateValidator ¶
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 ¶
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) History ¶
func (v *View) History() (*HistoryProvider, error)
History returns the views current history provider.
func (*View) RenderHTML ¶
RenderHTML renders out the views markup as a string wrapped with template.HTML
func (*View) UseHistory ¶
func (v *View) UseHistory(hs *HistoryProvider)
UseHistory sets the views HistoryProvider to effect navigation change.
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
type ViewStates ¶
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