xjs

package
v0.2.52 Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func (*Vapper) Back

func (t *Vapper) Back()

Back will cause the browser to go back to the previous page. It has the same effect as the user pressing the back button, and is just a wrapper around history.back()

func (*Vapper) CanNavigate

func (t *Vapper) CanNavigate(path string) bool

CanNavigate returns true if the specified path can be navigated by the router, and false otherwise

func (*Vapper) Config

func (t *Vapper) Config(cfg interface{})

func (*Vapper) Debug

func (t *Vapper) Debug(message ...interface{})

func (*Vapper) Delete

func (t *Vapper) Delete(key interface{})

func (*Vapper) Dispatch

func (t *Vapper) Dispatch(action flux.ActionInterface) chan struct{}

func (*Vapper) Fail

func (t *Vapper) Fail(err error)
func (t *Vapper) InterceptLinks()

InterceptLinks intercepts click events on links of the form <a href="/foo"></a> and calls router.Navigate("/foo") instead, which triggers the appropriate Handler instead of requesting a new page from the server. Since InterceptLinks works by setting event listeners in the DOM, you must call this function whenever the DOM is changed. Alternatively, you can set r.ShouldInterceptLinks to true, which will trigger this function whenever Start, Navigate, or Back are called, or when the onpopstate event is triggered. Even with r.ShouldInterceptLinks set to true, you may still need to call this function if you change the DOM manually without triggering a route.

func (*Vapper) Log

func (t *Vapper) Log(message ...interface{})

func (*Vapper) Logf

func (t *Vapper) Logf(format string, args ...interface{})
func (t *Vapper) Navigate(path string)

Navigate will trigger the handler associated with the given path and update window.location accordingly. If the browser supports history.pushState, that will be used. Otherwise, Navigate will set the hash component of window.location to the given path.

func (*Vapper) NotFound

func (t *Vapper) NotFound(handler Handler)

func (*Vapper) Route

func (t *Vapper) Route(path string, handler Handler)

HandleFunc will cause the router to call f whenever window.location.pathname (or window.location.hash, if history.pushState is not supported) matches path. path can contain any number of parameters which are denoted with curly brackets. So, for example, a path argument of "users/{id}" will be triggered when the user visits users/123 and will call the handler function with params["id"] = "123".

func (*Vapper) Store

func (t *Vapper) Store(store flux.StoreInterface)

func (*Vapper) Watch

func (t *Vapper) Watch(key interface{}, f func(done chan struct{}))

Types

type Context

type Context struct {
	// Params is the parameters from the url as a map of names to values.
	Params map[string]string
	// Path is the path that triggered this particular route. If the hash
	// fallback is being used, the value of path does not include the '#'
	// symbol.
	Path string
	// InitialLoad is true iff this route was triggered during the initial
	// page load. I.e. it is true if this is the first path that the browser
	// was visiting when the javascript finished loading.
	InitialLoad bool
	// QueryParams is the query params from the URL. Because params may be
	// repeated with different values, the value part of the map is a slice
	QueryParams map[string][]string
}

Context is used as an argument to Handlers

type Handler

type Handler interface {
	Handle(ctx *Context)
}

Handler is a function which is run in response to a specific route. A Handler takes a Context as an argument, which gives handler functions access to path parameters and other important information.

Jump to

Keyboard shortcuts

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