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 ¶
- func ApplyBindings(args ...interface{})
- func EnableSecureBinding()
- func Global() *js.Object
- func IsComputed(data interface{}) bool
- func IsObservable(data interface{}) bool
- func IsWritableObservable(data interface{}) bool
- func RegisterURLTemplateLoader()
- func Unwrap(ob *js.Object) *js.Object
- type ComponentsFuncs
- type Computed
- type Mapper
- func (m *Mapper) FromJS(data interface{}) (vm *ViewModel)
- func (m *Mapper) FromJSON(data string) (vm *ViewModel)
- func (m *Mapper) Ignore(properties ...string) *Mapper
- func (m *Mapper) Observe(properties ...string) *Mapper
- func (m *Mapper) Option(key string, value interface{}) *Mapper
- func (m *Mapper) Target(obj interface{}) *Mapper
- func (m *Mapper) ToJS(vm *ViewModel) *js.Object
- func (m *Mapper) ToJSON(vm *ViewModel) string
- type Observable
- type ObservableArray
- func (ob *ObservableArray) Index(i int) *js.Object
- func (ob *ObservableArray) IndexOf(data interface{}) int
- func (ob *ObservableArray) Length() int
- func (ob *ObservableArray) Pop() *js.Object
- func (ob *ObservableArray) Push(data interface{})
- func (ob *ObservableArray) Remove(item interface{}) *js.Object
- func (ob *ObservableArray) RemoveAll(items ...interface{}) *js.Object
- func (ob *ObservableArray) RemoveFunc(fn func(*js.Object) bool) *js.Object
- func (ob *ObservableArray) Reverse()
- func (ob *ObservableArray) Shift() *js.Object
- func (ob *ObservableArray) Sort()
- func (ob *ObservableArray) SortFunc(fn func(*js.Object, *js.Object))
- func (ob *ObservableArray) Splice(i, n int) *js.Object
- func (ob *ObservableArray) Unshift(data interface{})
- type Subscription
- type ValidatedObservable
- type ValidationFuncs
- type ViewModel
- type WritableComputed
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 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.
Types ¶
type ComponentsFuncs ¶
type ComponentsFuncs struct {
// contains filtered or unexported fields
}
func Components ¶
func Components() *ComponentsFuncs
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
type Mapper ¶
type Observable ¶
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:
- Making things respond after a certain delay
- 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) 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 (*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) Unshift ¶
func (ob *ObservableArray) Unshift(data interface{})
type Subscription ¶
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 ¶
func Validation ¶
func Validation() *ValidationFuncs
func (*ValidationFuncs) Init ¶
func (v *ValidationFuncs) Init(config js.M)
type WritableComputed ¶
type WritableComputed struct {
*Computed
}
func NewWritableComputed ¶
func NewWritableComputed(r func() interface{}, w func(interface{})) *WritableComputed