polymer

package module
v0.0.0-...-4385e9d Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2017 License: Apache-2.0 Imports: 11 Imported by: 15

README

polymer

GopherJS bindings for polymer

go get -u github.com/PalmStoneGames/polymer

Official Site

Project Repository

Documentation

Overview

The polymer library can be used to work with polymer using GopherJS instead of having to write straight up JavaScript. Simple examples to get started are available in the examples/ subfolder. It is highly recommend to go through them.

The polymer website itself also has a great deal of information on how to get started, most of the information available there also applies to the Go bindings of polymer.

Index

Constants

View Source
const DateTimeLocalFormat = "2006-01-02T15:04:05"

Variables

This section is empty.

Functions

func Decode

func Decode(jsVal *js.Object, target interface{}) error

Decode decodes a js object to the target it watches for fields on the structure tagged with polymer-decode Tags can be of the following format: `polymer-decode:"js_field_name"`

func Encode

func Encode(target interface{}) (*js.Object, bool)

Encode accepts a Go value and returns the encoded *js.Object, as well as a boolean that is true if the Go object was non-empty

func FlushDOM

func FlushDOM()

FlushDOM flushes pending changes to the DOM Insert, append, and remove operations are transacted lazily in certain cases for performance. In order to interrogate the DOM (for example, offsetHeight, getComputedStyle, etc.) immediately after one of these operations, call this function first.

func GetDocument

func GetDocument() dom.Document

func InterfaceToJsObject

func InterfaceToJsObject(target interface{}) *js.Object

func Log

func Log(args ...interface{})

func OnReady

func OnReady() <-chan struct{}

OnReady returns a channel that will be closed once polymer has been initialized

Types

type AsyncHandle

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

func Async

func Async(waitTime int, f func()) *AsyncHandle

Async calls the given callback asynchronously. If the specified wait time is -1, the callback will be ran with microtask timing (after the current method finishes, but before the next event from the event queue is processed) Otherwise, its ran waitTime milliseconds in the future. A waitTime of 1 can be useful to run a callback after all events currently in the queue have been processed. Returns a handle that can be used to cancel the task

type AutoBindGoTemplate

type AutoBindGoTemplate struct {
	*WrappedElement
}

func (*AutoBindGoTemplate) Bind

func (el *AutoBindGoTemplate) Bind(model BindInterface)

type BindInterface

type BindInterface interface {
	Notify(path ...string)
	// contains filtered or unexported methods
}

type BindProto

type BindProto struct {
	Element
	// contains filtered or unexported fields
}

func (*BindProto) Notify

func (p *BindProto) Notify(paths ...string)

type CustomRegistrationAttr

type CustomRegistrationAttr struct {
	Name  string
	Value interface{}
}

CustomRegistrationAttrs can be used to pass custom attributes to the generated javascript prototype

func WithBehaviors

func WithBehaviors(behaviors ...interface{}) CustomRegistrationAttr

WithBehaviors can be used to pass the protos of other polymer objects to be - If a string is passed, polymer will look for a global with that name, - If a *ElementDefinition is passed, it will be used as is - If a *js.Object is passed, it is set directly as behavior

func WithExtends

func WithExtends(extends string) CustomRegistrationAttr

WithExtends can be passed as option to Register to make an element extend another element

type DateTimeLocal

type DateTimeLocal time.Time

DateTimeLocal is a time.Time that properly encodes and decodes to the format expected datetime-local input fields The format is as follows, as per the format definition of the time package: "2006-01-02T15:04:05"

func (*DateTimeLocal) Decode

func (t *DateTimeLocal) Decode(val *js.Object) error

func (DateTimeLocal) Encode

func (t DateTimeLocal) Encode() (*js.Object, bool)

type Decoder

type Decoder interface {
	Decode(*js.Object) error
}

type Element

type Element interface {
	dom.Element

	// Root returns the local DOM root of the current element
	Root() Element

	// GetDistributedNodes returns the nodes distributed to a <content> insertion point
	// only returns useful results when called on a <content> element
	// Details can be found at https://www.polymer-project.org/1.0/docs/devguide/local-dom.html#distributed-children
	GetDistributedNodes() []dom.Node
	// GetDestinationInsertionPoints returns the <content> nodes this element will be distributed to
	// only returns useful results when called on an element that’s being distributed.
	// Details can be found at https://www.polymer-project.org/1.0/docs/devguide/local-dom.html#distributed-children
	GetDestinationInsertionPoints() []dom.Node
	// GetContentChildNodes accepts a css selector that points to a <content> node and returns all nodes that have been distributed to it
	// Details can be found at https://www.polymer-project.org/1.0/docs/devguide/local-dom.html#distributed-children
	GetContentChildNodes(selector string) []dom.Node
	// GetContentChildNodes accepts a css selector that points to a <content> node and returns all elements that have been distributed to it
	// Details can be found at https://www.polymer-project.org/1.0/docs/devguide/local-dom.html#distributed-children
	GetContentChildren(selector string) []Element

	// GetEffectiveChildNodes returns a list of effective child nodes for this element.
	// Effective child nodes are the child nodes of the element, with any insertion points replaced by their distributed child nodes.
	// Details can be found at https://www.polymer-project.org/1.0/docs/devguide/local-dom.html#effective-children
	GetEffectiveChildNodes() []dom.Node
	// GetEffectiveChildren returns a list of effective children for this element.
	// Effective children are the children of the element, with any insertion points replaced by their distributed children.
	// Details can be found at https://www.polymer-project.org/1.0/docs/devguide/local-dom.html#effective-children
	GetEffectiveChildren() []Element
	// QueryEffectiveChildren returns the first effective child that matches the selector
	// Effective children are the children of the element, with any insertion points replaced by their distributed children.
	// Details can be found at https://www.polymer-project.org/1.0/docs/devguide/local-dom.html#effective-children
	QueryEffectiveChildren(selector string) Element
	// QueryAllEffectiveChildren returns a slice of effective children that match selector
	// Effective children are the children of the element, with any insertion points replaced by their distributed children.
	// Details can be found at https://www.polymer-project.org/1.0/docs/devguide/local-dom.html#effective-children
	QueryAllEffectiveChildren(selector string) []Element

	// ObserveNodes sets up an observer that will be called when new nodes are added or removed from this Element
	// ObserveNodes  behaves slightly differently depending on the node being observed:
	// - If the node being observed is a content node, the callback is called when the content node’s distributed children change.
	// - For any other node, the callback is called when the node’s effective children change.
	ObserveNodes(func(*ObservationInfo)) *Observer
	// UnobserveNodes stops an observer from receiving notifications
	UnobserveNodes(*Observer)

	// SubscribeEvent subscribes to an event using the passed callback or channel
	// The callback/channel may be strongly typed, the types will be automatically decoded
	SubscribeEvent(event string, callback interface{}) *EventSubscription

	// UnsubscribeEvent unsubscribes from the event with the passed handle
	UnsubscribeEvent(sub *EventSubscription)
}

func WrapDOMElement

func WrapDOMElement(el dom.Element) Element

func WrapJSElement

func WrapJSElement(obj *js.Object) Element

type ElementDefinition

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

func Register

func Register(tagName string, proto Interface, customAttrs ...CustomRegistrationAttr) *ElementDefinition

Register makes polymer aware of a certain type Polymer will analyze the type and use it for the tag returned by TagName() The type will then be instantiated automatically when tags corresponding to TagName are created through any method

type Encoder

type Encoder interface {
	// Encode returns the encoded object as a *js.Object and a boolean that is true if the object was non-empty
	Encode() (*js.Object, bool)
}

type Event

type Event struct {
	Underlying *js.Object `polymer-decode:"underlying"`

	Type string    `polymer-decode:"event.type"`
	Time time.Time `polymer-decode:"event.timeStamp"`

	IsTrusted        bool `polymer-decode:"event.isTrusted"`
	Cancelable       bool `polymer-decode:"event.cancelable"`
	DefaultPrevented bool `polymer-decode:"event.defaultPrevented"`
	Bubbles          bool `polymer-decode:"event.bubbles"`
	CancelBubble     bool `polymer-decode:"event.cancelBubble"`

	LocalTarget Element   `polymer-decode:"localTarget"`
	RootTarget  Element   `polymer-decode:"rootTarget"`
	Path        []Element `polymer-decode:"path"`
}

func (*Event) PreventDefault

func (e *Event) PreventDefault()

func (*Event) StopPropagation

func (e *Event) StopPropagation()

type EventSubscription

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

type Interface

type Interface interface {
	// Created is part of the lifecycle callbacks
	// It is called when the element is initially created, before the constructor
	// Details can be found at https://www.polymer-project.org/1.0/docs/devguide/registering-elements.html#lifecycle-callbacks
	Created()

	// Ready is part of the lifecycle callbacks
	// The ready callback is called when an element’s local DOM is ready.
	// It is called after the element’s template has been stamped and all elements inside the element’s local DOM have been configured
	// (with values bound from parents, deserialized attributes, or else default values) and had their ready method called.
	// Details can be found at https://www.polymer-project.org/1.0/docs/devguide/registering-elements.html#ready-method
	Ready()

	// Attached is part of the lifecycle callbacks
	// It is called when the element is attached to the DOM
	// Details can be found at https://www.polymer-project.org/1.0/docs/devguide/registering-elements.html#lifecycle-callbacks
	Attached()

	// Detached is part of the lifecycle callbacks
	// It is called when the element is detached from the DOM
	// Details can be found at https://www.polymer-project.org/1.0/docs/devguide/registering-elements.html#lifecycle-callbacks
	Detached()
	// contains filtered or unexported methods
}

Interface represents the interface implemented by all type prototypes Any type implementing this interface can be registered with polymer.Register() Most of this interface can be implemented by embedded polymer.Proto The notable exception to this is TagName, which must always be manually implemented

type MouseEvent

type MouseEvent struct {
	Event

	MovementX int `polymer-decode:"event.movementX"`
	MovementY int `polymer-decode:"event.movementY"`
	OffsetX   int `polymer-decode:"event.offsetX"`
	OffsetY   int `polymer-decode:"event.offsetY"`
	PageX     int `polymer-decode:"event.pageX"`
	PageY     int `polymer-decode:"event.pageY"`

	FromElement Element `polymer-decode:"event.fromElement"`
	ToElement   Element `polymer-decode:"event.toElement"`
}

type ObservationInfo

type ObservationInfo struct {
	Observer *Observer

	AddedNodes, RemovedNodes []dom.Node
}

ObservationInfo is the structure used to hand data to ObserveNodes callbacks

type Observer

type Observer struct {
	Element Element
	// contains filtered or unexported fields
}

Observer is the structure used to track an observation using ObserveNodes/UnobserveNodes

type PropertyChangedEvent

type PropertyChangedEvent struct {
	Event
	JSValue *js.Object `polymer-decode:"event.detail.value"`
}

type Proto

type Proto struct {
	Element
	// contains filtered or unexported fields
}

Proto represents a prototype for a polymer type it's meant to be embedded by the structures used to implements polymer tags

func (*Proto) Attached

func (p *Proto) Attached()

func (*Proto) CancelAsync

func (p *Proto) CancelAsync(handle *AsyncHandle)

func (*Proto) Created

func (p *Proto) Created()

func (*Proto) Detached

func (p *Proto) Detached()

func (*Proto) Extends

func (p *Proto) Extends() string

func (*Proto) Fire

func (p *Proto) Fire(event string, val interface{})

func (*Proto) Notify

func (p *Proto) Notify(paths ...string)

Notify notifies polymer that a value has changed

func (*Proto) Ready

func (p *Proto) Ready()

func (*Proto) This

func (p *Proto) This() *js.Object

This returns the underlying js object corresponding to the `this` magic value in javascript Unlike Underlying(), this object is not wrapped by Polymer.dom()

type Window

type Window interface {
	dom.Window

	// SubscribeEvent subscribes to an event using the passed callback or channel
	// The callback/channel may be strongly typed, the types will be automatically decoded
	SubscribeEvent(event string, callback interface{}) *EventSubscription

	// UnsubscribeEvent unsubscribes from the event with the passed handle
	UnsubscribeEvent(sub *EventSubscription)
}

func GetWindow

func GetWindow() Window

type WrappedElement

type WrappedElement struct {
	dom.Element
	UnwrappedElement dom.Element
}

func (*WrappedElement) AppendChild

func (el *WrappedElement) AppendChild(node dom.Node)

func (*WrappedElement) GetAttribute

func (el *WrappedElement) GetAttribute(name string) string

func (*WrappedElement) GetAttributeNS

func (el *WrappedElement) GetAttributeNS(ns string, name string) string

func (*WrappedElement) GetBoundingClientRect

func (el *WrappedElement) GetBoundingClientRect() dom.ClientRect

func (*WrappedElement) GetContentChildNodes

func (el *WrappedElement) GetContentChildNodes(selector string) []dom.Node

GetContentChildNodes accepts a css selector that points to a <content> node and returns all nodes that have been distributed to it Details can be found at https://www.polymer-project.org/1.0/docs/devguide/local-dom.html#distributed-children

func (*WrappedElement) GetContentChildren

func (el *WrappedElement) GetContentChildren(selector string) []Element

GetContentChildNodes accepts a css selector that points to a <content> node and returns all elements that have been distributed to it Details can be found at https://www.polymer-project.org/1.0/docs/devguide/local-dom.html#distributed-children

func (*WrappedElement) GetDestinationInsertionPoints

func (el *WrappedElement) GetDestinationInsertionPoints() []dom.Node

GetDestinationInsertionPoints returns the <content> nodes this element will be distributed to only returns useful results when called on an element that’s being distributed. Details can be found at https://www.polymer-project.org/1.0/docs/devguide/local-dom.html#distributed-children

func (*WrappedElement) GetDistributedNodes

func (el *WrappedElement) GetDistributedNodes() []dom.Node

GetDistributedNodes returns the nodes distributed to a <content> insertion point only returns useful results when called on a <content> element Details can be found at https://www.polymer-project.org/1.0/docs/devguide/local-dom.html#distributed-children

func (*WrappedElement) GetEffectiveChildNodes

func (el *WrappedElement) GetEffectiveChildNodes() []dom.Node

GetEffectiveChildNodes returns a list of effective child nodes for this element. Effective child nodes are the child nodes of the element, with any insertion points replaced by their distributed child nodes. Details can be found at https://www.polymer-project.org/1.0/docs/devguide/local-dom.html#effective-children

func (*WrappedElement) GetEffectiveChildren

func (el *WrappedElement) GetEffectiveChildren() []Element

GetEffectiveChildren returns a list of effective children for this element. Effective children are the children of the element, with any insertion points replaced by their distributed children. Details can be found at https://www.polymer-project.org/1.0/docs/devguide/local-dom.html#effective-children

func (*WrappedElement) GetElementsByClassName

func (el *WrappedElement) GetElementsByClassName(name string) []dom.Element

func (*WrappedElement) GetElementsByTagName

func (el *WrappedElement) GetElementsByTagName(name string) []dom.Element

func (*WrappedElement) GetElementsByTagNameNS

func (el *WrappedElement) GetElementsByTagNameNS(ns, name string) []dom.Element

func (*WrappedElement) ID

func (el *WrappedElement) ID() string

func (*WrappedElement) InsertBefore

func (el *WrappedElement) InsertBefore(which dom.Node, before dom.Node)

func (*WrappedElement) ObserveNodes

func (el *WrappedElement) ObserveNodes(f func(*ObservationInfo)) *Observer

ObserveNodes sets up an observer that will be called when new nodes are added or removed from this Element ObserveNodes behaves slightly differently depending on the node being observed: - If the node being observed is a content node, the callback is called when the content node’s distributed children change. - For any other node, the callback is called when the node’s effective children change.

func (*WrappedElement) ParentElement

func (el *WrappedElement) ParentElement() dom.Element

func (*WrappedElement) QueryAllEffectiveChildren

func (el *WrappedElement) QueryAllEffectiveChildren(selector string) []Element

QueryAllEffectiveChildren returns a slice of effective children that match selector Effective children are the children of the element, with any insertion points replaced by their distributed children. Details can be found at https://www.polymer-project.org/1.0/docs/devguide/local-dom.html#effective-children

func (*WrappedElement) QueryEffectiveChildren

func (el *WrappedElement) QueryEffectiveChildren(selector string) Element

QueryEffectiveChildren returns the first effective child that matches the selector Effective children are the children of the element, with any insertion points replaced by their distributed children. Details can be found at https://www.polymer-project.org/1.0/docs/devguide/local-dom.html#effective-children

func (*WrappedElement) QuerySelector

func (el *WrappedElement) QuerySelector(sel string) dom.Element

func (*WrappedElement) QuerySelectorAll

func (el *WrappedElement) QuerySelectorAll(sel string) []dom.Element

func (*WrappedElement) Root

func (el *WrappedElement) Root() Element

Root returns the local DOM root of the current element

func (*WrappedElement) SubscribeEvent

func (el *WrappedElement) SubscribeEvent(event string, callback interface{}) *EventSubscription

func (*WrappedElement) TagName

func (el *WrappedElement) TagName() string

func (*WrappedElement) UnobserveNodes

func (el *WrappedElement) UnobserveNodes(obs *Observer)

UnobserveNodes stops an observer from receiving notifications

func (*WrappedElement) UnsubscribeEvent

func (el *WrappedElement) UnsubscribeEvent(sub *EventSubscription)

Jump to

Keyboard shortcuts

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