app: github.com/maxence-charriere/app/pkg/app Index | Files

package app

import "github.com/maxence-charriere/app/pkg/app"

Index

Package Files

app.go app_other.go bind.go compo.go handler.go storage.go

Variables

var (
    // DefaultPath is the path to the component to be  loaded when no path is
    // specified.
    DefaultPath string

    // NotFoundPath is the path to the component to be  loaded when an non
    // imported component is requested.
    NotFoundPath = "/app.notfound"

    // LocalStorage is a storage that uses the browser local storage associated
    // to the document origin. Data stored are encrypted and has no expiration
    // time.
    LocalStorage BrowserStorage

    // SessionStorage is a storage that uses the browser session storage
    // associated to the document origin. Data stored are encrypted and expire
    // when the page session ends.
    SessionStorage BrowserStorage
)

func Emit Uses

func Emit(msg string, args ...interface{})

Emit emits a message that triggers the associated bindings.

func Import Uses

func Import(c ...Compo)

Import imports the given components into the app. Components must be imported in order the be used by the app package. This allows components to be created dynamically when they are found into markup.

func LocationURL Uses

func LocationURL() *url.URL

LocationURL returns the current location url.

func Navigate(rawurl string)

Navigate navigates to the given URL.

func Reload Uses

func Reload()

Reload reloads the current page.

func Render Uses

func Render(c Compo)

Render renders the given component. It should be called whenever a component is modified. Render is always executed on the UI goroutine.

It panics if called before Run.

func Run Uses

func Run()

Run runs the app with the loaded URL.

func UI Uses

func UI(f func())

UI calls a function on the UI goroutine.

func WindowSize Uses

func WindowSize() (w, h int)

WindowSize returns the window width and height.

type BindContext Uses

type BindContext interface {
    context.Context

    // Get returns a value from the current binding chain.
    Get(k string) interface{}

    // Lookup looks for a value from the current binding chain.
    Lookup(k string) (interface{}, bool)

    // Set sets a value in the current binding chain.
    Set(k string, v interface{})

    // Cancel stop the binding chain execution.
    Cancel(error)
}

BindContext is the interface that describes a context passed when a binding is executed.

type Binding Uses

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

Binding represents a serie of actions that are executed successively when a message is emitted.

func Bind Uses

func Bind(msg string, c Compo) *Binding

Bind creates a binding between a message and the given component.

func (*Binding) Defer Uses

func (b *Binding) Defer(d time.Duration) *Binding

Defer postpones the execution of the binding after the given duration. If a message occurs while the binding is deferred, arguments and duration are updated with the latest message emitted.

func (*Binding) Do Uses

func (b *Binding) Do(f interface{}) *Binding

Do adds the given function to the actions of the binding. The function will be executed on the ui goroutine.

If the function is the first one to be added to the binding, its arguments are mapped with the ones emitted with the binded message.

The binding execution context can be passed if the function first argument is a BindContext or a context.Context.

It panics if f is not a function.

func (*Binding) DoAsync Uses

func (b *Binding) DoAsync(f interface{}) *Binding

DoAsync adds the given function to the actions of the binding. The function will be executed on the goroutine used to perform the binding.

If the function is the first one to be added to the binding, its arguments are mapped with the ones emitted with the binded message.

The binding execution context can be passed if the function first argument is a BindContext or a context.Context.

It panics if f is not a function.

func (*Binding) Wait Uses

func (b *Binding) Wait(d time.Duration) *Binding

Wait delays the execution of the next function registered with Do or DoOnUI for the given duration.

func (*Binding) WhenCancel Uses

func (b *Binding) WhenCancel(f func(BindContext))

WhenCancel setup the given function to be called when the binding is cancelled with a BindContext. The function will be executed on the UI goroutine.

type BrowserStorage Uses

type BrowserStorage interface {
    // Set sets the item to the given key. The item must be json convertible in
    // json.
    Set(k string, i interface{}) error

    // Get gets the item associated to the given key and store it in the given
    // value.
    // It returns an error if v is not a pointer.
    Get(k string, v interface{}) error

    // Del deletes the item associated with the given key.
    Del(k string)

    // Clear deletes all items.
    Clear()
}

BrowserStorage is the interface that describes a web browser storage.

type Compo Uses

type Compo interface {
    // Render must return a HTML5 string. It supports standard Go html/template
    // API. The pipeline is based on the component struct. See
    // https://golang.org/pkg/text/template and
    // https://golang.org/pkg/html/template for template usage.
    Render() string
}

Compo is the interface that describes a component. Must be implemented on a non empty struct pointer.

type CompoWithExtendedRender Uses

type CompoWithExtendedRender interface {
    // Funcs returns a map of funcs to use when rendering a component.
    // Funcs named raw, json and time are reserved.
    // They handle raw html code, json conversions and time format.
    // They can't be overloaded.
    // See https://golang.org/pkg/text/template/#Template.Funcs for more details.
    Funcs() map[string]interface{}
}

CompoWithExtendedRender is the interface that wraps Funcs method.

type Dismounter Uses

type Dismounter interface {
    // OnDismount is called when a component is dismounted.
    // App.Render should not be called inside.
    OnDismount()
}

Dismounter is the interface that wraps OnDismount method.

type Handler Uses

type Handler struct {
    http.Handler

    // The app author.
    Author string

    // The app description.
    Description string

    // The app keywords.
    Keywords []string

    // The text displayed while loading a page.
    LoadingLabel string

    // Additional headers to be added in <head></head>.
    Headers []string

    // The app name.
    Name string

    // The progressive app mode configuration.
    ProgressiveApp ProgressiveAppConfig

    // The he path of the web directory. Default is web.
    WebDir string
    // contains filtered or unexported fields
}

Handler is a http handler that serves UI components created with this package.

func (*Handler) ServeHTTP Uses

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Mounter Uses

type Mounter interface {
    // OnMount is called when a component is mounted.
    // App.Render should not be called inside.
    OnMount()
}

Mounter is the interface that wraps OnMount method.

type ProgressiveAppConfig Uses

type ProgressiveAppConfig struct {
    // Enforces landscape mode.
    LanscapeMode bool

    // Provides a short human-readable name for the application. This is
    // intended for when there is insufficient space to display the full name of
    // the web application, like device homescreens.
    //
    // Default is the app name where space are replaces by '-'.
    ShortName string

    // Defines the navigation scope of this website's context. This restricts
    // what web pages can be viewed while the manifest is applied. If the user
    // navigates outside the scope, it returns to a normal web page inside a
    // browser tab/window.
    //
    // Default is "/".
    Scope string

    // The URL that loads when a user launches the application (e.g. when added
    // to home screen), typically the index.
    // Default is "/".
    StartURL string

    // Defines the default theme color for an application. This sometimes
    // affects how the OS displays the site (e.g., on Android's task switcher,
    // the theme color surrounds the site).
    ThemeColor string
}

ProgressiveAppConfig represents the configuration used to describe a progressive app.

type ZeroCompo Uses

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

ZeroCompo is the type to use as base for empty components. Every instances of an empty struct is given the same memory address, which causes problem for indexing components. ZeroCompo have a placeholder field to avoid that.

Package app imports 12 packages (graph). Updated 2019-10-13. Refresh now. Tools for package owners.