|
| 1 | +--- |
| 2 | +title: API Reference |
| 3 | +description: Quick-lookup index of TKO's public API. |
| 4 | +--- |
| 5 | + |
| 6 | +# API Reference |
| 7 | + |
| 8 | +Quick-lookup table for TKO's public API. Each entry links to its detailed documentation. |
| 9 | + |
| 10 | +## Observables |
| 11 | + |
| 12 | +| Function | Description | |
| 13 | +|----------|-------------| |
| 14 | +| `ko.observable(value?)` | Create a reactive value. [Docs](/observables/) | |
| 15 | +| `ko.observableArray(array?)` | Observable wrapper around an array with mutation methods. [Docs](/observables/observablearrays/) | |
| 16 | +| `ko.isObservable(value)` | Check if a value is an observable. [Docs](/observables/utilities/) | |
| 17 | +| `ko.isObservableArray(value)` | Check if a value is an observable array. [Docs](/observables/utilities/) | |
| 18 | +| `ko.isWritableObservable(value)` | Check if a value is a writable observable. [Docs](/observables/utilities/) | |
| 19 | +| `ko.isSubscribable(value)` | Check if a value is any subscribable type. [Docs](/observables/utilities/) | |
| 20 | +| `ko.peek(value)` | Read an observable's value without creating a dependency. | |
| 21 | +| `ko.unwrap(value)` | Read an observable's value, or return a plain value as-is. [Docs](/observables/utilities/) | |
| 22 | +| `ko.toJS(object)` | Clone an object tree, replacing observables with their values. [Docs](/observables/utilities/) | |
| 23 | +| `ko.toJSON(object, replacer?, space?)` | `ko.toJS` + `JSON.stringify`. [Docs](/observables/utilities/) | |
| 24 | + |
| 25 | +## Computed |
| 26 | + |
| 27 | +| Function | Description | |
| 28 | +|----------|-------------| |
| 29 | +| `ko.computed(evaluatorOrOptions, owner?, options?)` | Create a value that depends on other observables. Accepts a function or `{ read, write }` options object. [Docs](/computed/computedobservables/) | |
| 30 | +| `ko.pureComputed(evaluator, owner?)` | Computed that sleeps when it has no subscribers. [Docs](/computed/computed-pure/) | |
| 31 | +| `ko.isComputed(value)` | Check if a value is a computed observable. [Docs](/observables/utilities/) | |
| 32 | +| `ko.isPureComputed(value)` | Check if a value is a pure computed. | |
| 33 | +| `ko.ignoreDependencies(callback, owner?, args?)` | Run a function without tracking dependencies. | |
| 34 | +| `ko.when(predicate, callback?, context?)` | Resolve when the predicate becomes truthy. Returns a promise, or calls callback if provided. [Docs](/observables/) | |
| 35 | + |
| 36 | +## Subscribable instance methods |
| 37 | + |
| 38 | +Every observable, computed, and observable array inherits these from `subscribable.fn`: |
| 39 | + |
| 40 | +| Method | Description | |
| 41 | +|--------|-------------| |
| 42 | +| `.subscribe(callback, target?, event?)` | Register a callback for changes. [Docs](/observables/) | |
| 43 | +| `.when(testOrValue, returnValue?)` | Promise that resolves when the test passes. [Docs](/observables/) | |
| 44 | +| `.yet(testOrValue, returnValue?)` | Promise that resolves when the test *fails* (negated `.when`). [Docs](/observables/) | |
| 45 | +| `.next()` | Promise that resolves on the next value change. [Docs](/observables/) | |
| 46 | +| `.once(callback)` | Call the callback on the next change, then auto-dispose. [Docs](/observables/) | |
| 47 | +| `.peek()` | Read the current value without creating a dependency. | |
| 48 | +| `.dispose()` | Tear down all subscriptions. | |
| 49 | + |
| 50 | +## Extenders |
| 51 | + |
| 52 | +| Function | Description | |
| 53 | +|----------|-------------| |
| 54 | +| `observable.extend(extenders)` | Apply extenders to an observable or computed. [Docs](/observables/extenders/) | |
| 55 | +| `rateLimit` | Throttle change notifications. [Docs](/observables/ratelimit-observable/) | |
| 56 | +| `notify: 'always'` | Force notification even when value hasn't changed. [Docs](/observables/) | |
| 57 | + |
| 58 | +## Bindings |
| 59 | + |
| 60 | +| Function | Description | |
| 61 | +|----------|-------------| |
| 62 | +| `ko.applyBindings(viewModel, rootNode?)` | Activate bindings on a DOM subtree. [Docs](/observables/#activating-knockout) | |
| 63 | +| `ko.applyBindingsToNode(node, bindings, viewModelOrContext?)` | Apply bindings to a single node programmatically. | |
| 64 | +| `ko.applyBindingsToDescendants(viewModelOrContext, rootNode)` | Apply bindings to descendants only (used in custom bindings). [Docs](/binding-context/custom-bindings-controlling-descendant-bindings/) | |
| 65 | +| `ko.contextFor(node)` | Get the binding context for a DOM node. | |
| 66 | +| `ko.dataFor(node)` | Get the view model bound to a DOM node. | |
| 67 | +| `ko.cleanNode(node)` | Remove all TKO data and bindings from a node. | |
| 68 | +| `ko.bindingHandlers` | Registry of built-in and custom binding handlers. [Docs](/binding-context/custom-bindings/) | |
| 69 | +| `ko.bindingEvent` | Binding lifecycle event constants (e.g., `childrenComplete`, `descendantsComplete`). | |
| 70 | +| `ko.BindingHandler` | Base class for class-based custom binding handlers. [Docs](/binding-context/custom-bindings/) | |
| 71 | +| `ko.AsyncBindingHandler` | Async variant of `BindingHandler` for bindings that load resources. [Docs](/binding-context/custom-bindings/) | |
| 72 | + |
| 73 | +### Built-in bindings |
| 74 | + |
| 75 | +**Text & HTML:** [`text`](/bindings/text-binding/), [`html`](/bindings/html-binding/), [`textInput`](/bindings/textinput-binding/), [`value`](/bindings/value-binding/) |
| 76 | + |
| 77 | +**Appearance:** [`visible`](/bindings/visible-binding/), `hidden`, [`css`](/bindings/css-binding/) (alias: `class`), [`style`](/bindings/style-binding/), [`attr`](/bindings/attr-binding/) |
| 78 | + |
| 79 | +**Control flow:** [`if`](/bindings/if-binding/), [`ifnot`](/bindings/ifnot-binding/) (alias: `unless`), `else`, `elseif`, [`foreach`](/bindings/foreach-binding/) (alias: `each`), [`with`](/bindings/with-binding/), [`template`](/bindings/template-binding/) |
| 80 | + |
| 81 | +**Context:** `let`, `using` |
| 82 | + |
| 83 | +**Form:** [`click`](/bindings/click-binding/), [`event`](/bindings/event-binding/) (alias: `on`), [`submit`](/bindings/submit-binding/), [`enable`](/bindings/enable-binding/), [`disable`](/bindings/disable-binding/), [`checked`](/bindings/checked-binding/), `checkedValue`, [`options`](/bindings/options-binding/), [`selectedOptions`](/bindings/selectedoptions-binding/), [`hasfocus`](/bindings/hasfocus-binding/), [`uniqueName`](/bindings/uniquename-binding/) |
| 84 | + |
| 85 | +**Components:** `component`, `slot` |
| 86 | + |
| 87 | +**Lifecycle:** `descendantsComplete` |
| 88 | + |
| 89 | +## Components |
| 90 | + |
| 91 | +| Function | Description | |
| 92 | +|----------|-------------| |
| 93 | +| `ko.components.register(name, config)` | Register a component. [Docs](/components/component-registration/) | |
| 94 | +| `ko.components.get(name)` | Retrieve a registered component definition. [Docs](/components/component-loaders/) | |
| 95 | +| `ko.components.isRegistered(name)` | Check if a component name is registered. | |
| 96 | +| `ko.components.unregister(name)` | Remove a component registration. | |
| 97 | +| `ko.components.clearCachedDefinition(name)` | Clear a cached component definition. | |
| 98 | +| `ko.Component` | Base class for class-based components (`ComponentABC`). [Docs](/components/) | |
| 99 | + |
| 100 | +## JSX (build.reference only) |
| 101 | + |
| 102 | +| Function | Description | |
| 103 | +|----------|-------------| |
| 104 | +| `ko.jsx.createElement(tag, props, ...children)` | Create a JSX element. Used as the JSX factory. | |
| 105 | +| `ko.jsx.Fragment` | Fragment component for grouping elements without a wrapper node. | |
| 106 | +| `ko.jsx.render(jsx)` | Render JSX to DOM nodes. Returns `{ node, dispose }`. | |
| 107 | + |
| 108 | +## DOM disposal |
| 109 | + |
| 110 | +| Function | Description | |
| 111 | +|----------|-------------| |
| 112 | +| `ko.domNodeDisposal.addDisposeCallback(node, callback)` | Run a callback when a DOM node is removed by TKO. | |
| 113 | +| `ko.domNodeDisposal.removeDisposeCallback(node, callback)` | Remove a previously registered disposal callback. | |
| 114 | + |
| 115 | +## Extensibility |
| 116 | + |
| 117 | +| Function | Description | |
| 118 | +|----------|-------------| |
| 119 | +| `ko.subscribable.fn` | Prototype for all subscribables. [Docs](/observables/utilities/) | |
| 120 | +| `ko.observable.fn` | Prototype for all observables — add methods here. [Docs](/observables/utilities/) | |
| 121 | +| `ko.observableArray.fn` | Prototype for observable arrays (`remove`, `replace`, etc.). [Docs](/observables/utilities/) | |
| 122 | +| `ko.computed.fn` | Prototype for all computeds. [Docs](/observables/utilities/) | |
| 123 | +| `ko.tasks` | Microtask scheduler for batching async work. | |
0 commit comments