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 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 Disposer
- 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
- func (ob *Observable) Extend(params js.M) *Observable
- func (ob *Observable) Get() *js.Object
- func (ob *Observable) NotifyAlways()
- func (ob *Observable) RateLimit(timeframeMS int, notifyWhenChangesStop ...bool)
- func (ob *Observable) Set(data interface{})
- func (ob *Observable) Subscribe(fn func(*js.Object)) *Subscription
- 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{})
In case you’re wondering what the parameters to ko.applyBindings do,
the first parameter says what view model object you want to use with the declarative bindings it activates
Optionally, you can pass a second parameter to define which part of the document you want to search for data-bind attributes.
For example,
ko.applyBindings(myViewModel, document.getElementById('someElementId')).
This restricts the activation to the element with ID someElementId and its descendants, which is useful if you want to have multiple view models and associate each with a different region of the page.
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
returns true for observables, observable arrays, and all computed observables.
func IsWritableObservable ¶
func IsWritableObservable(data interface{}) bool
returns true for observables, observable arrays, and writable computed observables
func RegisterURLTemplateLoader ¶
func RegisterURLTemplateLoader()
RegisterURLTemplateLoader register 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 ¶
type Observable struct {
// contains filtered or unexported fields
}
func NewObservable ¶
func NewObservable(data ...interface{}) *Observable
func (*Observable) Extend ¶
func (ob *Observable) Extend(params js.M) *Observable
func (*Observable) Get ¶
func (ob *Observable) Get() *js.Object
func (*Observable) NotifyAlways ¶
func (ob *Observable) NotifyAlways()
When a computed observable returns a primitive value (a number, string, boolean, or null), the dependencies of the observable are normally only notified if the value actually changed. However, it is possible to use the built-in notify extender to ensure that a computed observable’s subscribers are always notified on an update, even if the value is the same.
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(data ...interface{}) *ObservableArray
func (*ObservableArray) IndexOf ¶
func (ob *ObservableArray) IndexOf(data interface{}) int
adds a new item to the end of array
func (*ObservableArray) Length ¶
func (ob *ObservableArray) Length() int
func (*ObservableArray) Pop ¶
func (ob *ObservableArray) Pop() *js.Object
removes the last value from the array and returns it
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
removes the first value from the array and returns it
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
removes and returns a given number of elements starting from a given index. For example,
myObservableArray.splice(1, 3)
removes three elements starting from index position 1 (i.e., the 2nd, 3rd, and 4th elements) and returns them as an array.
func (*ObservableArray) Unshift ¶
func (ob *ObservableArray) Unshift(data interface{})
inserts a new item at the beginning of the array
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