ko

package module
v0.0.0-...-8a38c2f Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2015 License: MIT Imports: 3 Imported by: 0

README

GopherJS-Ko

GopherJS bindings to KnockoutJS

Install

go get github.com/mibitzi/gopherjs-ko

Documentation

For documentation, see http://godoc.org/github.com/mibitzi/gopherjs-ko

Documentation

Overview

Package ko implements bindings to KnockoutJS. It also has bindings for the Knockout Validation library found on https://github.com/Knockout-Contrib/Knockout-Validation Using EnableSecureBinding make KnockoutJS works under CSP environments.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyBindings

func ApplyBindings(args ...interface{})

func EnableSecureBinding

func EnableSecureBinding()
var options = {
   attribute: "data-bind",        // default "data-sbind"
   globals: window,               // default {}
   bindings: ko.bindingHandlers,  // default ko.bindingHandlers
   noVirtualElements: false       // default true
};

ko.bindingProvider.instance = new ko.secureBindingsProvider(options);

Knockout Secure Binding (KSB) is a binding provider for Knockout that can be used with a Content Security Policy (CSP) that disables eval and new Function.

Use this function to make gopherjs-ko works under chrome app/extensions.

Must load knockout-secure-binding.min.js first: https://github.com/brianmhunt/knockout-secure-binding

func Global

func Global() *js.Object

func IsComputed

func IsComputed(data interface{}) bool

func IsObservable

func IsObservable(data interface{}) bool

func IsWritableObservable

func IsWritableObservable(data interface{}) bool

func RegisterURLTemplateLoader

func RegisterURLTemplateLoader()

RegisterURLTemplateLoader registers a new template loader which can be used to load template files from a webserver. To use it you need to pass a map with a `url` key as template argument to your component:

"template":  js.M{"url": "form.html"}

This loader requires jQuery.

func Unwrap

func Unwrap(ob *js.Object) *js.Object

Types

type ComponentsFuncs

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

func Components

func Components() *ComponentsFuncs

func (*ComponentsFuncs) Register

func (co *ComponentsFuncs) Register(name string, params js.M)

func (*ComponentsFuncs) RegisterEx

func (co *ComponentsFuncs) RegisterEx(name string, vmfunc func(params *js.Object) interface{}, template, cssRules string)

RegisterEx is an easy form to create KnockoutJS components

name is the component name
vmfunc is the ViewModel creator
template is the html tempalte for the component
cssRules would be directly embeded in the final html page, which can be ""

type Computed

type Computed struct {
	*Observable
}

func NewComputed

func NewComputed(fn func() interface{}) *Computed

func (*Computed) Dispose

func (ob *Computed) Dispose()

func (*Computed) Peek

func (ob *Computed) Peek() *js.Object

type Mapper

type Mapper struct {
	*js.Object
	// contains filtered or unexported fields
}

func Mapping

func Mapping() *Mapper

func (*Mapper) FromJS

func (m *Mapper) FromJS(data interface{}) (vm *ViewModel)

func (*Mapper) FromJSON

func (m *Mapper) FromJSON(data string) (vm *ViewModel)

func (*Mapper) Ignore

func (m *Mapper) Ignore(properties ...string) *Mapper

Ignoring certain properties using “ignore”

func (*Mapper) Observe

func (m *Mapper) Observe(properties ...string) *Mapper

Observing only certain properties using “observe”

func (*Mapper) Option

func (m *Mapper) Option(key string, value interface{}) *Mapper

Set mapping options

func (*Mapper) Target

func (m *Mapper) Target(obj interface{}) *Mapper

Specifying the target to update, can be a *ViewModel or a *js.Object or a struct with *js.Object embeded which is a ViewModel then

func (*Mapper) ToJS

func (m *Mapper) ToJS(vm *ViewModel) *js.Object

func (*Mapper) ToJSON

func (m *Mapper) ToJSON(vm *ViewModel) string

type Observable

type Observable struct {
	*js.Object
}

func NewObservable

func NewObservable(args ...interface{}) *Observable

func (*Observable) Extend

func (ob *Observable) Extend(params js.M) *Observable

func (*Observable) Get

func (ob *Observable) Get() *js.Object

func (*Observable) RateLimit

func (ob *Observable) RateLimit(timeframeMS int, notifyWhenChangesStop ...bool)

The rateLimit extender, however, causes an observable to suppress and delay change notifications for a specified period of time. A rate-limited observable therefore updates dependencies asynchronously.

The rateLimit extender can be applied to any type of observable, including observable arrays and computed observables. The main use cases for rate-limiting are:

  1. Making things respond after a certain delay
  2. Combining multiple changes into a single update

when "notifyWhenChangesStop" is true change envent will be fired only after no change event detects anymore. "notifyWhenChangesStop" default is false, then it works under "notifyAtFixedRate" mode, at most one change in one timeframe.

func (*Observable) Set

func (ob *Observable) Set(data interface{})

func (*Observable) Subscribe

func (ob *Observable) Subscribe(fn func(*js.Object)) *Subscription

type ObservableArray

type ObservableArray struct {
	*Observable
}

func NewObservableArray

func NewObservableArray(args ...interface{}) *ObservableArray

func (*ObservableArray) Index

func (ob *ObservableArray) Index(i int) *js.Object

func (*ObservableArray) IndexOf

func (ob *ObservableArray) IndexOf(data interface{}) int

func (*ObservableArray) Length

func (ob *ObservableArray) Length() int

func (*ObservableArray) Pop

func (ob *ObservableArray) Pop() *js.Object

func (*ObservableArray) Push

func (ob *ObservableArray) Push(data interface{})

func (*ObservableArray) Remove

func (ob *ObservableArray) Remove(item interface{}) *js.Object

func (*ObservableArray) RemoveAll

func (ob *ObservableArray) RemoveAll(items ...interface{}) *js.Object

func (*ObservableArray) RemoveFunc

func (ob *ObservableArray) RemoveFunc(fn func(*js.Object) bool) *js.Object

func (*ObservableArray) Reverse

func (ob *ObservableArray) Reverse()

func (*ObservableArray) Shift

func (ob *ObservableArray) Shift() *js.Object

func (*ObservableArray) Sort

func (ob *ObservableArray) Sort()

func (*ObservableArray) SortFunc

func (ob *ObservableArray) SortFunc(fn func(*js.Object, *js.Object))

func (*ObservableArray) Splice

func (ob *ObservableArray) Splice(i, n int) *js.Object

func (*ObservableArray) Unshift

func (ob *ObservableArray) Unshift(data interface{})

type Subscription

type Subscription struct {
	*js.Object
}

func (*Subscription) Dispose

func (s *Subscription) Dispose()

type ValidatedObservable

type ValidatedObservable struct {
	*Observable
}

func NewValidatedObservable

func NewValidatedObservable(data interface{}) *ValidatedObservable

func (*ValidatedObservable) IsValid

func (v *ValidatedObservable) IsValid() bool

type ValidationFuncs

type ValidationFuncs struct {
	*js.Object
}

func Validation

func Validation() *ValidationFuncs

func (*ValidationFuncs) Init

func (v *ValidationFuncs) Init(config js.M)

type ViewModel

type ViewModel struct {
	*js.Object
}

ViewModel can be used to wrap ko vm object

func (*ViewModel) Get

func (v *ViewModel) Get(keyPath string) *js.Object

func (*ViewModel) Set

func (v *ViewModel) Set(keyPath string, value interface{})

func (*ViewModel) Update

func (v *ViewModel) Update(data interface{}) *ViewModel

type WritableComputed

type WritableComputed struct {
	*Computed
}

func NewWritableComputed

func NewWritableComputed(r func() interface{}, w func(interface{})) *WritableComputed

Jump to

Keyboard shortcuts

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