domrepeat

package
v0.0.0-...-aecb3d9 Latest Latest
Warning

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

Go to latest
Published: May 6, 2018 License: MIT Imports: 3 Imported by: 0

README

dom-repeat element

Stamps out the delegate element from an slice.

usage

If you want to repeat elements from an slice of objects.

//UserItem is the object that will be passed to the delegate element
type UserItem struct {
	UserName  string	
	AvatarURL string
}

//UserDelegate is an element that will be stamped out by the dom-repeat
type UserDelegate struct {
	golymer.Element
	User *UserItem //the data that will be passed to the Delegate
}

...

//the my-elem has just an dom-repeat child, with user-delegate element as the delegate,
//it passes the UserItems slice to the dom-repeat,
//and the UserDelegate will reference the data item as 'User' (not the default 'Item')
var myTemplate = golymer.NewTemplate(`
<dom-repeat id="repeat" delegate="user-delegate" items="{{UserItems}}" item-as="User"></dom-repeat>
`)

type MyElem struct {
	golymer.Element
	UserItems []*UserItem
	repeat    *domrepeat.DomRepeat
}

To add new UserItems, just append to the slice myElem.UserItems = append(myElem.UserItems, newUserItem, anotherUserItem), and then you must signalize to the dom-repeat element that something has changed, with the ItemsInserted method.

myElem.repeat.ItemsInserted(len(myElem.UserItems)-2, 2) //the last two rows were inserted

The same with removing items: myElem.UserItems = myElem.UserItems[3:]

myElem.repeat.ItemsRemoved(0, 3) //the first three items where removed

Material Design buttons repeat example:

	rb.Buttons = []*button{
		&button{"click1", "red"},
		&button{"click2", "blue"},
		&button{"click3", "green"},
		&button{"click4", "yellow"},
	}

repeat-buttons

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DomRepeat

type DomRepeat struct {
	golymer.Element
	Delegate string
	ItemAs   string
	Items    interface{}
}

DomRepeat is an element that stamps and binds objects from an model

func (*DomRepeat) ConnectedCallback

func (dr *DomRepeat) ConnectedCallback()

ConnectedCallback gets the template child

func (*DomRepeat) ItemsInserted

func (dr *DomRepeat) ItemsInserted(row, count int)

ItemsInserted is a function to indicate to the DomRepeat that the underlying data has changed new items where inserted, starting on `row` and next `count` items

func (*DomRepeat) ItemsRemoved

func (dr *DomRepeat) ItemsRemoved(row, count int)

ItemsRemoved is a function to indicate to the DomRepeat that the underlying data has changed items where removed, starting on `row` and also the next `count` items

func (*DomRepeat) ObserverItems

func (dr *DomRepeat) ObserverItems(oldValue, newValue interface{})

ObserverItems controls if the Items assigned are a slice type

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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