Class: kb.utils
Defined in: | src/core/utils.coffee |
Overview
Library of general-purpose utilities
Class Method Summary
- ~ (ko.observable|ko.observableArray) wrappedObservable(instance) Dual-purpose getter/setter for retrieving and storing the observable on an instance that returns a ko.observable instead of 'this'.
- ~ (Model|Collection) wrappedObject(obj) Dual-purpose getter/setter for retrieving and storing the Model or Collection on an owner.
- ~ (Model|ViewModel) wrappedModel(view_model) Dual-purpose getter/setter for retrieving and storing the Model on a ViewModel.
- ~ (kb.Store) wrappedStore(obj) Dual-purpose getter/setter for retrieving and storing a kb.Store on an owner.
- ~ (kb.Factory) wrappedFactory(obj) Dual-purpose getter/setter for retrieving and storing a kb.Factory on an owner.
- ~ (kb.EventWatcher) wrappedEventWatcher(obj) Dual-purpose getter/setter for retrieving and storing a kb.EventWatcher on an owner.
- . (void) valueType(observable) Retrieves the value stored in a ko.observable.
- . (String) pathJoin(path1, path2) Helper to join a dot-deliminated path.
- . (Object) optionsPathJoin(options, path) Helper to join a dot-deliminated path with the path on options and returns a new options object with the result.
- . (void) inferCreator(value, factory, path) Helper to find the creator constructor or function from a factory or ORM solution
- . (void) createFromDefaultCreator(obj, options) Creates an observable based on a value's type.
Class Method Details
~
(ko.observable|ko.observableArray)
wrappedObservable(instance)
~
(void)
wrappedObservable(instance, observable)
Dual-purpose getter/setter for retrieving and storing the observable on an instance that returns a ko.observable instead of 'this'. Relevant for:
- kb.CollectionObservable kb.Observable kb.DefaultObservable kb.FormattedObservable kb.LocalizedObservable * kb.TriggeredObservable
Examples:
var ShortDateLocalizer = kb.LocalizedObservable.extend({
constructor: function(value, options, view_model) {
kb.LocalizedObservable.prototype.constructor.apply(this, arguments);
return kb.utils.wrappedObservable(this);
}
});
~
(Model|Collection)
wrappedObject(obj)
~
(void)
wrappedObject(obj, value)
Dual-purpose getter/setter for retrieving and storing the Model or Collection on an owner.
Examples:
var model = kb.utils.wrappedObject(view_model);
var collection = kb.utils.wrappedObject(collection_observable);
~
(Model|ViewModel)
wrappedModel(view_model)
~
(void)
wrappedModel(view_model, model)
Dual-purpose getter/setter for retrieving and storing the Model on a ViewModel.
~
(kb.Store)
wrappedStore(obj)
~
(void)
wrappedStore(obj, store)
Dual-purpose getter/setter for retrieving and storing a kb.Store on an owner.
Examples:
var co = kb.collectionObservable(new Backbone.Collection());
var co_selected_options = kb.collectionObservable(new Backbone.Collection(), {
store: kb.utils.wrappedStore(co)
});
~
(kb.Factory)
wrappedFactory(obj)
~
(void)
wrappedFactory(obj, factory)
Dual-purpose getter/setter for retrieving and storing a kb.Factory on an owner.
~
(kb.EventWatcher)
wrappedEventWatcher(obj)
~
(void)
wrappedEventWatcher(obj, event_watcher)
Dual-purpose getter/setter for retrieving and storing a kb.EventWatcher on an owner.
.
(void)
valueType(observable)
Retrieves the value stored in a ko.observable.
Examples:
var view_model = kb.viewModel(new Model({simple_attr: null, model_attr: null}), {factories: {model_attr: kb.ViewModel});
kb.utils.valueType(view_model.simple_attr); // kb.TYPE_SIMPLE
kb.utils.valueType(view_model.model_attr); // kb.TYPE_MODEL
.
(String)
pathJoin(path1, path2)
Helper to join a dot-deliminated path.
Examples:
kb.utils.pathJoin('models', 'name'); // 'models.name'
.
(Object)
optionsPathJoin(options, path)
Helper to join a dot-deliminated path with the path on options and returns a new options object with the result.
Examples:
this.friends = kb.collectionObservable(model.get('friends'), kb.utils.optionsPathJoin(options, 'friends'));
.
(void)
inferCreator(value, factory, path)
Helper to find the creator constructor or function from a factory or ORM solution
.
(void)
createFromDefaultCreator(obj, options)
Creates an observable based on a value's type.