Class: kb

Defined in: src/core/kb.coffee

Variables Summary

VERSION =
'1.2.3'

Knockback library semantic version

TYPE_UNKNOWN =
0

Stored value type is not known like null/undefined (could be observed as a Model or a Collection or a simple type)

TYPE_SIMPLE =
1

Stored value type is simple like a String or Number -> observable type: ko.observable

TYPE_ARRAY =
2

Stored value type is an Array -> observable type: ko.observableArray

TYPE_MODEL =
3

Stored value type is a Model -> observable type: ViewModel

TYPE_COLLECTION =
4

Stored value type is a Collection -> observable type: kb.CollectionObservable

Class Method Summary

Class Method Details

. (void) wasReleased(obj)

Checks if an object has been released.

Parameters:

  • obj ( Any ) the object to release and also release its keys

. (void) isReleaseable(obj, depth = 0)

Checks if an object can be released. Used to perform minimal nested releasing on objects by checking if self or next level contained items can be released.

Parameters:

  • obj ( Any ) the object to release and also release its keys

. (void) release(obj)

Releases any type of view model or observable or items in an array using the conventions of release(), destroy(), dispose().

Examples:

var view_model = kb.viewModel(model);
kb.release(view_model); view_model = null;

var todos = kb.collectionObservable(collection);
kb.release(todos); todos = null;

Parameters:

  • obj ( Any ) the object to release and also release its keys

. (void) releaseKeys(obj)

Releases and clears all of the keys on an object using the conventions of release(), destroy(), dispose() without releasing the top level object itself.

. (void) releaseOnNodeRemove(view_model, node)

Binds a callback to the node that releases the view model when the node is removed using ko.removeNode.

ko.utils.domNodeDisposal.addDisposeCallback(node, function() { kb.release(view_model)} );

Examples:

The hard way to set up automatic calling of 'kb.release(view_model)' when the bound element is released.

var el = $('<div data-bind="name: name"></div>')[0];
var view_model = kb.viewModel(new Backbone.Model({name: 'Bob'}));
ko.applyBindings(view_model, el);
kb.releaseOnNodeRemove(view_model, el);
...
ko.removeNode(el); // removes el from the DOM and calls kb.release(view_model)

. (void) renderTemplate(template, view_model, options = {})

Renders a template and binds a callback to the node that releases the view model when the node is removed using ko.removeNode.

NOTE: if you provide an afterRender method on the View Model and do not provide afterRender in the options, afterRender will be called with the following signature: afterRender(element) which differs from the Knockout signture of afterRender(elements)

Examples:

The easy way to set up automatic calling of 'kb.release(view_model)' when the bound element is released.

var el = kb.renderTemplate('my_template', kb.viewModel(new Backbone.Model({name: 'Bob'})));
...
ko.removeNode(el); // removes el from the DOM and calls kb.release(view_model)

. (void) applyBindings(view_model, node)

Applies bindings and binds a callback to the node that releases the view model when the node is removed using ko.removeNode.

Examples:

The easy way to set up automatic calling of 'kb.release(view_model)' when the bound element is released.

var el = $('<div data-bind="name: name"></div>')[0];
kb.applyBindings(kb.viewModel(new Backbone.Model({name: 'Bob'})), el);
...
ko.removeNode(el); // removes el from the DOM and calls kb.release(view_model)

. (void) getValue(model, key, args)

. (void) setValue(model, key, value)

    Quickly fuzzy find classes, mixins, methods, file:

    Control the navigation frame:

    You can focus and blur the search input: