API Reference
API Reference
Section titled “API Reference”Quick-lookup table for TKO’s public API. Each entry links to its detailed documentation.
Observables
Section titled “Observables”| Function | Description |
|---|---|
ko.observable(value?) | Create a reactive value. Docs |
ko.observableArray(array?) | Observable wrapper around an array with mutation methods. Docs |
ko.isObservable(value) | Check if a value is an observable. Docs |
ko.isObservableArray(value) | Check if a value is an observable array. Docs |
ko.isWritableObservable(value) | Check if a value is a writable observable. Docs |
ko.isSubscribable(value) | Check if a value is any subscribable type. Docs |
ko.peek(value) | Read an observable’s value without creating a dependency. |
ko.unwrap(value) | Read an observable’s value, or return a plain value as-is. Docs |
ko.toJS(object) | Clone an object tree, replacing observables with their values. Docs |
ko.toJSON(object, replacer?, space?) | ko.toJS + JSON.stringify. Docs |
Computed
Section titled “Computed”| Function | Description |
|---|---|
ko.computed(evaluatorOrOptions, owner?, options?) | Create a value that depends on other observables. Accepts a function or { read, write } options object. Docs |
ko.pureComputed(evaluator, owner?) | Computed that sleeps when it has no subscribers. Docs |
ko.isComputed(value) | Check if a value is a computed observable. Docs |
ko.isPureComputed(value) | Check if a value is a pure computed. |
ko.ignoreDependencies(callback, owner?, args?) | Run a function without tracking dependencies. |
ko.when(predicate, callback?, context?) | Resolve when the predicate becomes truthy. Returns a promise, or calls callback if provided. Docs |
Subscribable instance methods
Section titled “Subscribable instance methods”Every observable, computed, and observable array inherits these from subscribable.fn:
| Method | Description |
|---|---|
.subscribe(callback, target?, event?) | Register a callback for changes. Docs |
.when(testOrValue, returnValue?) | Promise that resolves when the test passes. Docs |
.yet(testOrValue, returnValue?) | Promise that resolves when the test fails (negated .when). Docs |
.next() | Promise that resolves on the next value change. Docs |
.once(callback) | Call the callback on the next change, then auto-dispose. Docs |
.peek() | Read the current value without creating a dependency. |
.dispose() | Tear down all subscriptions. |
Extenders
Section titled “Extenders”| Function | Description |
|---|---|
observable.extend(extenders) | Apply extenders to an observable or computed. Docs |
rateLimit | Throttle change notifications. Docs |
notify: 'always' | Force notification even when value hasn’t changed. Docs |
Bindings
Section titled “Bindings”| Function | Description |
|---|---|
ko.applyBindings(viewModel, rootNode?) | Activate bindings on a DOM subtree. Docs |
ko.applyBindingsToNode(node, bindings, viewModelOrContext?) | Apply bindings to a single node programmatically. |
ko.applyBindingsToDescendants(viewModelOrContext, rootNode) | Apply bindings to descendants only (used in custom bindings). Docs |
ko.contextFor(node) | Get the binding context for a DOM node. |
ko.dataFor(node) | Get the view model bound to a DOM node. |
ko.cleanNode(node) | Remove all TKO data and bindings from a node. |
ko.bindingHandlers | Registry of built-in and custom binding handlers. Docs |
ko.bindingEvent | Binding lifecycle event constants (e.g., childrenComplete, descendantsComplete). |
ko.BindingHandler | Base class for class-based custom binding handlers. Docs |
ko.AsyncBindingHandler | Async variant of BindingHandler for bindings that load resources. Docs |
Built-in bindings
Section titled “Built-in bindings”Text & HTML: text, html, textInput, value
Appearance: visible, hidden, css (alias: class), style, attr
Control flow: if, ifnot (alias: unless), else, elseif, foreach (alias: each), with, template
Context: let, using
Form: click, event (alias: on), submit, enable, disable, checked, checkedValue, options, selectedOptions, hasfocus, uniqueName
Components: component, slot
Lifecycle: descendantsComplete
Components
Section titled “Components”| Function | Description |
|---|---|
ko.components.register(name, config) | Register a component. Docs |
ko.components.get(name) | Retrieve a registered component definition. Docs |
ko.components.isRegistered(name) | Check if a component name is registered. |
ko.components.unregister(name) | Remove a component registration. |
ko.components.clearCachedDefinition(name) | Clear a cached component definition. |
ko.Component | Base class for class-based components (ComponentABC). Docs |
JSX (build.reference only)
Section titled “JSX (build.reference only)”| Function | Description |
|---|---|
ko.jsx.createElement(tag, props, ...children) | Create a JSX element. Used as the JSX factory. |
ko.jsx.Fragment | Fragment component for grouping elements without a wrapper node. |
ko.jsx.render(jsx) | Render JSX to DOM nodes. Returns { node, dispose }. |
DOM disposal
Section titled “DOM disposal”| Function | Description |
|---|---|
ko.domNodeDisposal.addDisposeCallback(node, callback) | Run a callback when a DOM node is removed by TKO. |
ko.domNodeDisposal.removeDisposeCallback(node, callback) | Remove a previously registered disposal callback. |
Extensibility
Section titled “Extensibility”| Function | Description |
|---|---|
ko.subscribable.fn | Prototype for all subscribables. Docs |
ko.observable.fn | Prototype for all observables — add methods here. Docs |
ko.observableArray.fn | Prototype for observable arrays (remove, replace, etc.). Docs |
ko.computed.fn | Prototype for all computeds. Docs |
ko.tasks | Microtask scheduler for batching async work. |