Skip to content
Browse files

Upgraded to latest Knockback

  • Loading branch information...
1 parent 92c3024 commit b61f3d870aa4bbd96409ca055187ff315ba53a46 Kevin Malakoff committed Sep 24, 2012
View
12 knockback-inspector.js
@@ -181,13 +181,11 @@ kbi.NodeViewModel = (function() {
this.node = node_value;
model = kb.utils.wrappedModel(this.node);
this.attribute_names = ko.observableArray(model ? _.keys(model.attributes) : []);
- } else if ((typeof node_value.get === 'function') && (typeof node_value.trigger === 'function')) {
- if (node_value.models) {
- this.node = kb.collectionObservable(node_value);
- } else {
- this.node = kb.viewModel(node_value);
- this.attribute_names = ko.observableArray(_.keys(node_value.attributes));
- }
+ } else if (kb.utils.hasCollectionSignature(node_value)) {
+ this.node = kb.collectionObservable(node_value);
+ } else if (kb.utils.hasModelSignature(node_value)) {
+ this.node = kb.viewModel(node_value);
+ this.attribute_names = ko.observableArray(_.keys(node_value.attributes));
}
return;
}
View
2 knockback-inspector.min.js
@@ -3,4 +3,4 @@
(c) 2011, 2012 Kevin Malakoff - http://kmalakoff.github.com/knockback/
License: MIT (http://www.opensource.org/licenses/mit-license.php)
Dependencies: Knockout.js, Backbone.js, and Underscore.js.
-*/(function(){return function(e){return typeof define=="function"&&define.amd?define("knockback-inspector",["underscore","backbone","knockout","knockback"],e):e.call(this)}(function(){var e,t,n,r,i,s={}.hasOwnProperty,o=function(e,t){function r(){this.constructor=e}for(var n in t)s.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e};if(!this._&&typeof require!="undefined")try{i=require("lodash")}catch(u){i=require("underscore")}else i=this._;return i=i.hasOwnProperty("_")?i._:i,e=!this.Backbone&&typeof require!="undefined"?require("backbone"):this.Backbone,r=!this.ko&&typeof require!="undefined"?require("knockout"):this.ko,t=!this.kb&&typeof require!="undefined"?require("knockback"):this.kb,n=this.kbi=typeof exports!="undefined"?exports:{},this.kbi.VERSION="0.1.6",n.TemplateSource=function(){function e(e,t){this.template_generator=e,this.binding_context=t!=null?t:{}}return e.prototype.data=function(e,t){return arguments.length===1?this.binding_context[e]:this.binding_context[e]=t},e.prototype.text=function(){if(arguments.length>0)throw"kbi.TemplateSource: unexpected writing to template source";return this.template_generator.viewText(this.binding_context)},e}(),n.TemplateEngine=function(e){function t(){this.allowTemplateRewriting=!1,this.generators={kbi_array_node:n.ArrayNodeViewGenerator,kbi_model_node:n.ModelNodeViewGenerator,kbi_collection_node:n.CollectionNodeViewGenerator}}return o(t,e),t.prototype.generator=function(e,t){return arguments.length===1?this.generators[e]:this.generators[e]=t},t.prototype.makeTemplateSource=function(e){return this.generators.hasOwnProperty(e)?new n.TemplateSource(new this.generators[e](e)):t.__super__.makeTemplateSource.apply(this,arguments)},t.prototype.renderTemplateSource=function(e,n,r){var i,s;for(i in n)s=n[i],e.data(i,s);return t.__super__.renderTemplateSource.apply(this,arguments)},t}(r.nativeTemplateEngine),n.FetchedModel=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return o(t,e),t.prototype.parse=function(e){var t,r,s,o,u;t={};for(s in e)u=e[s],i.isObject(u)?(o=new n.FetchedModel,t[s]=o.set(o.parse(u))):i.isArray(u)?(r=new n.FetchedCollection,t[s]=r.reset(r.parse(u))):t[s]=u;return t},t}(e.Model),n.FetchedCollection=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return o(t,e),t.prototype.model=n.FetchedModel,t.prototype.parse=function(e){var t;return t=e.results?e.results:e,i.map(e.results,function(e){var t;return t=new n.FetchedModel,t.set(t.parse(e))})},t}(e.Collection),n.NodeViewModel=function(){function e(e,n,s){var o,u;this.name=e,this.node=s,this.opened=r.observable(n),u=r.utils.unwrapObservable(this.node),u instanceof t.ViewModel?(this.node=u,o=t.utils.wrappedModel(this.node),this.attribute_names=r.observableArray(o?i.keys(o.attributes):[])):typeof u.get=="function"&&typeof u.trigger=="function"&&(u.models?this.node=t.collectionObservable(u):(this.node=t.viewModel(u),this.attribute_names=r.observableArray(i.keys(u.attributes))));return}return e}(),n.nodeViewModel=n.nvm=function(e,t,r){return new n.NodeViewModel(e,t,r)},n.ArrayNodeViewGenerator=function(){function e(e){this.template_name=e}return e.prototype.viewText=function(){return""+this.nodeStart()+"\n"+this.nodeManipulator()+"\n <!-- ko if: opened -->\n <!-- ko foreach: node -->\n <!-- ko if: (kb.utils.valueType($data) == kb.TYPE_SIMPLE) -->\n "+this.attributeEditor()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($data) == kb.TYPE_ARRAY) -->\n "+this.arrayTree()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($data) == kb.TYPE_MODEL) -->\n "+this.modelTree()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($data) == kb.TYPE_COLLECTION) -->\n "+this.collectionTree()+"\n <!-- /ko -->\n\n <!-- /ko -->\n <!-- /ko -->\n"+this.nodeEnd()},e.prototype.nodeStart=function(){return"<li class='kbi' data-bind=\"css: {opened: opened, closed: !opened()}\">"},e.prototype.nodeManipulator=function(){return"<div class='array' data-bind=\"click: function(){ opened(!opened()) }\">\n <span data-bind=\"text: (opened() ? '- ' : '+ ' )\"></span>\n <span data-bind=\"text: name + '[]'\"></span>\n</div>"},e.prototype.attributeEditor=function(){return"<fieldset class='kbi'>\n <label data-bind=\"text: '['+$index()+']'\"></label>\n <input type='text' data-bind=\"value: $data, valueUpdate: 'keyup'\">\n</fieldset>"},e.prototype.arrayTree=function(){return""+n.ViewHTML.arrayTree("'['+$index()+']'",!1,"$data")},e.prototype.modelTree=function(){return""+n.ViewHTML.modelTree("'['+$index()+']'",!1,"$data")},e.prototype.collectionTree=function(){return""+n.ViewHTML.collectionTree("'['+$index()+']'",!1,"$data")},e.prototype.nodeEnd=function(){return""},e}(),n.CollectionNodeViewGenerator=function(){function e(e){this.template_name=e}return e.prototype.viewText=function(){return""+this.nodeStart()+"\n"+this.nodeManipulator()+"\n <!-- ko if: opened -->\n <!-- ko foreach: node -->\n "+this.modelNode()+"\n <!-- /ko -->\n <!-- /ko -->\n"+this.nodeEnd()},e.prototype.nodeStart=function(){return"<li class='kbi' data-bind=\"css: {opened: opened, closed: !opened()}\">"},e.prototype.nodeManipulator=function(){return"<div class='collection' data-bind=\"click: function(){ opened(!opened()) }\">\n <span data-bind=\"text: (opened() ? '- ' : '+ ' )\"></span>\n <span data-bind=\"text: name\"></span>\n</div>"},e.prototype.modelNode=function(){return""+n.ViewHTML.modelTree("'['+$index()+']'",!1,"$data")},e.prototype.nodeEnd=function(){return"</li>"},e}(),n.ModelNodeViewGenerator=function(){function e(e){this.template_name=e}return e.prototype.viewText=function(){return""+this.nodeStart()+"\n"+this.nodeManipulator()+"\n <!-- ko if: opened -->\n <!-- ko foreach: attribute_names -->\n <!-- ko if: (kb.utils.valueType($parent.node[$data]) == kb.TYPE_SIMPLE) -->\n "+this.attributeEditor()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($parent.node[$data]) == kb.TYPE_ARRAY) -->\n "+this.arrayTree()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($parent.node[$data]) == kb.TYPE_MODEL) -->\n "+this.modelTree()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($parent.node[$data]) == kb.TYPE_COLLECTION) -->\n "+this.collectionTree()+"\n <!-- /ko -->\n\n <!-- /ko -->\n <!-- /ko -->\n"+this.nodeEnd()},e.prototype.nodeStart=function(){return"<li class='kbi' data-bind=\"css: {opened: opened, closed: !opened()}\">"},e.prototype.nodeManipulator=function(){return"<div class='collection' data-bind=\"click: function(){ opened(!opened()) }\">\n <span data-bind=\"text: (opened() ? '- ' : '+ ' )\"></span>\n <span data-bind=\"text: name\"></span>\n</div>"},e.prototype.attributeEditor=function(){return"<fieldset class='kbi'>\n <label data-bind=\"text: $data\"></label>\n <input type='text' data-bind=\"value: $parent.node[$data], valueUpdate: 'keyup'\">\n</fieldset>"},e.prototype.arrayTree=function(){return""+n.ViewHTML.arrayTree("$data",!1,"$parent.node[$data]")},e.prototype.modelTree=function(){return""+n.ViewHTML.modelTree("$data",!1,"$parent.node[$data]")},e.prototype.collectionTree=function(){return""+n.ViewHTML.collectionTree("$data+'[]'",!0,"$parent.node[$data]")},e.prototype.nodeEnd=function(){return"</li>"},e}(),n.ViewHTML=function(){function e(){}return e.arrayTree=function(e,t,n){return"<ul class='kbi' data-bind=\"template: {name: 'kbi_array_node', data: kbi.nvm("+e+", "+t+", "+n+')}"></ul>'},e.modelTree=function(e,t,n){return"<ul class='kbi' data-bind=\"template: {name: 'kbi_model_node', data: kbi.nvm("+e+", "+t+", "+n+')}"></ul>'},e.collectionTree=function(e,t,n){return"<ul class='kbi' data-bind=\"template: {name: 'kbi_collection_node', data: kbi.nvm("+e+", "+t+", "+n+')}"></ul>'},e}(),n})}).call(this);
+*/(function(){return function(e){return typeof define=="function"&&define.amd?define("knockback-inspector",["underscore","backbone","knockout","knockback"],e):e.call(this)}(function(){var e,t,n,r,i,s={}.hasOwnProperty,o=function(e,t){function r(){this.constructor=e}for(var n in t)s.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e};if(!this._&&typeof require!="undefined")try{i=require("lodash")}catch(u){i=require("underscore")}else i=this._;return i=i.hasOwnProperty("_")?i._:i,e=!this.Backbone&&typeof require!="undefined"?require("backbone"):this.Backbone,r=!this.ko&&typeof require!="undefined"?require("knockout"):this.ko,t=!this.kb&&typeof require!="undefined"?require("knockback"):this.kb,n=this.kbi=typeof exports!="undefined"?exports:{},this.kbi.VERSION="0.1.6",n.TemplateSource=function(){function e(e,t){this.template_generator=e,this.binding_context=t!=null?t:{}}return e.prototype.data=function(e,t){return arguments.length===1?this.binding_context[e]:this.binding_context[e]=t},e.prototype.text=function(){if(arguments.length>0)throw"kbi.TemplateSource: unexpected writing to template source";return this.template_generator.viewText(this.binding_context)},e}(),n.TemplateEngine=function(e){function t(){this.allowTemplateRewriting=!1,this.generators={kbi_array_node:n.ArrayNodeViewGenerator,kbi_model_node:n.ModelNodeViewGenerator,kbi_collection_node:n.CollectionNodeViewGenerator}}return o(t,e),t.prototype.generator=function(e,t){return arguments.length===1?this.generators[e]:this.generators[e]=t},t.prototype.makeTemplateSource=function(e){return this.generators.hasOwnProperty(e)?new n.TemplateSource(new this.generators[e](e)):t.__super__.makeTemplateSource.apply(this,arguments)},t.prototype.renderTemplateSource=function(e,n,r){var i,s;for(i in n)s=n[i],e.data(i,s);return t.__super__.renderTemplateSource.apply(this,arguments)},t}(r.nativeTemplateEngine),n.FetchedModel=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return o(t,e),t.prototype.parse=function(e){var t,r,s,o,u;t={};for(s in e)u=e[s],i.isObject(u)?(o=new n.FetchedModel,t[s]=o.set(o.parse(u))):i.isArray(u)?(r=new n.FetchedCollection,t[s]=r.reset(r.parse(u))):t[s]=u;return t},t}(e.Model),n.FetchedCollection=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return o(t,e),t.prototype.model=n.FetchedModel,t.prototype.parse=function(e){var t;return t=e.results?e.results:e,i.map(e.results,function(e){var t;return t=new n.FetchedModel,t.set(t.parse(e))})},t}(e.Collection),n.NodeViewModel=function(){function e(e,n,s){var o,u;this.name=e,this.node=s,this.opened=r.observable(n),u=r.utils.unwrapObservable(this.node),u instanceof t.ViewModel?(this.node=u,o=t.utils.wrappedModel(this.node),this.attribute_names=r.observableArray(o?i.keys(o.attributes):[])):t.utils.hasCollectionSignature(u)?this.node=t.collectionObservable(u):t.utils.hasModelSignature(u)&&(this.node=t.viewModel(u),this.attribute_names=r.observableArray(i.keys(u.attributes)));return}return e}(),n.nodeViewModel=n.nvm=function(e,t,r){return new n.NodeViewModel(e,t,r)},n.ArrayNodeViewGenerator=function(){function e(e){this.template_name=e}return e.prototype.viewText=function(){return""+this.nodeStart()+"\n"+this.nodeManipulator()+"\n <!-- ko if: opened -->\n <!-- ko foreach: node -->\n <!-- ko if: (kb.utils.valueType($data) == kb.TYPE_SIMPLE) -->\n "+this.attributeEditor()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($data) == kb.TYPE_ARRAY) -->\n "+this.arrayTree()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($data) == kb.TYPE_MODEL) -->\n "+this.modelTree()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($data) == kb.TYPE_COLLECTION) -->\n "+this.collectionTree()+"\n <!-- /ko -->\n\n <!-- /ko -->\n <!-- /ko -->\n"+this.nodeEnd()},e.prototype.nodeStart=function(){return"<li class='kbi' data-bind=\"css: {opened: opened, closed: !opened()}\">"},e.prototype.nodeManipulator=function(){return"<div class='array' data-bind=\"click: function(){ opened(!opened()) }\">\n <span data-bind=\"text: (opened() ? '- ' : '+ ' )\"></span>\n <span data-bind=\"text: name + '[]'\"></span>\n</div>"},e.prototype.attributeEditor=function(){return"<fieldset class='kbi'>\n <label data-bind=\"text: '['+$index()+']'\"></label>\n <input type='text' data-bind=\"value: $data, valueUpdate: 'keyup'\">\n</fieldset>"},e.prototype.arrayTree=function(){return""+n.ViewHTML.arrayTree("'['+$index()+']'",!1,"$data")},e.prototype.modelTree=function(){return""+n.ViewHTML.modelTree("'['+$index()+']'",!1,"$data")},e.prototype.collectionTree=function(){return""+n.ViewHTML.collectionTree("'['+$index()+']'",!1,"$data")},e.prototype.nodeEnd=function(){return""},e}(),n.CollectionNodeViewGenerator=function(){function e(e){this.template_name=e}return e.prototype.viewText=function(){return""+this.nodeStart()+"\n"+this.nodeManipulator()+"\n <!-- ko if: opened -->\n <!-- ko foreach: node -->\n "+this.modelNode()+"\n <!-- /ko -->\n <!-- /ko -->\n"+this.nodeEnd()},e.prototype.nodeStart=function(){return"<li class='kbi' data-bind=\"css: {opened: opened, closed: !opened()}\">"},e.prototype.nodeManipulator=function(){return"<div class='collection' data-bind=\"click: function(){ opened(!opened()) }\">\n <span data-bind=\"text: (opened() ? '- ' : '+ ' )\"></span>\n <span data-bind=\"text: name\"></span>\n</div>"},e.prototype.modelNode=function(){return""+n.ViewHTML.modelTree("'['+$index()+']'",!1,"$data")},e.prototype.nodeEnd=function(){return"</li>"},e}(),n.ModelNodeViewGenerator=function(){function e(e){this.template_name=e}return e.prototype.viewText=function(){return""+this.nodeStart()+"\n"+this.nodeManipulator()+"\n <!-- ko if: opened -->\n <!-- ko foreach: attribute_names -->\n <!-- ko if: (kb.utils.valueType($parent.node[$data]) == kb.TYPE_SIMPLE) -->\n "+this.attributeEditor()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($parent.node[$data]) == kb.TYPE_ARRAY) -->\n "+this.arrayTree()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($parent.node[$data]) == kb.TYPE_MODEL) -->\n "+this.modelTree()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($parent.node[$data]) == kb.TYPE_COLLECTION) -->\n "+this.collectionTree()+"\n <!-- /ko -->\n\n <!-- /ko -->\n <!-- /ko -->\n"+this.nodeEnd()},e.prototype.nodeStart=function(){return"<li class='kbi' data-bind=\"css: {opened: opened, closed: !opened()}\">"},e.prototype.nodeManipulator=function(){return"<div class='collection' data-bind=\"click: function(){ opened(!opened()) }\">\n <span data-bind=\"text: (opened() ? '- ' : '+ ' )\"></span>\n <span data-bind=\"text: name\"></span>\n</div>"},e.prototype.attributeEditor=function(){return"<fieldset class='kbi'>\n <label data-bind=\"text: $data\"></label>\n <input type='text' data-bind=\"value: $parent.node[$data], valueUpdate: 'keyup'\">\n</fieldset>"},e.prototype.arrayTree=function(){return""+n.ViewHTML.arrayTree("$data",!1,"$parent.node[$data]")},e.prototype.modelTree=function(){return""+n.ViewHTML.modelTree("$data",!1,"$parent.node[$data]")},e.prototype.collectionTree=function(){return""+n.ViewHTML.collectionTree("$data+'[]'",!0,"$parent.node[$data]")},e.prototype.nodeEnd=function(){return"</li>"},e}(),n.ViewHTML=function(){function e(){}return e.arrayTree=function(e,t,n){return"<ul class='kbi' data-bind=\"template: {name: 'kbi_array_node', data: kbi.nvm("+e+", "+t+", "+n+')}"></ul>'},e.modelTree=function(e,t,n){return"<ul class='kbi' data-bind=\"template: {name: 'kbi_model_node', data: kbi.nvm("+e+", "+t+", "+n+')}"></ul>'},e.collectionTree=function(e,t,n){return"<ul class='kbi' data-bind=\"template: {name: 'kbi_collection_node', data: kbi.nvm("+e+", "+t+", "+n+')}"></ul>'},e}(),n})}).call(this);
View
2 package.json
@@ -27,7 +27,7 @@
"knockout-client": ">=2.1.0",
"backbone-relational": ">=0.6.0",
"backbone-modelref": ">=0.1.5",
- "knockback": ">=0.16.6",
+ "knockback": ">=0.16.7",
"lodash": ">=0.6.1"
},
View
12 packages/npm/knockback-inspector.js
@@ -181,13 +181,11 @@ kbi.NodeViewModel = (function() {
this.node = node_value;
model = kb.utils.wrappedModel(this.node);
this.attribute_names = ko.observableArray(model ? _.keys(model.attributes) : []);
- } else if ((typeof node_value.get === 'function') && (typeof node_value.trigger === 'function')) {
- if (node_value.models) {
- this.node = kb.collectionObservable(node_value);
- } else {
- this.node = kb.viewModel(node_value);
- this.attribute_names = ko.observableArray(_.keys(node_value.attributes));
- }
+ } else if (kb.utils.hasCollectionSignature(node_value)) {
+ this.node = kb.collectionObservable(node_value);
+ } else if (kb.utils.hasModelSignature(node_value)) {
+ this.node = kb.viewModel(node_value);
+ this.attribute_names = ko.observableArray(_.keys(node_value.attributes));
}
return;
}
View
2 packages/npm/knockback-inspector.min.js
@@ -3,4 +3,4 @@
(c) 2011, 2012 Kevin Malakoff - http://kmalakoff.github.com/knockback/
License: MIT (http://www.opensource.org/licenses/mit-license.php)
Dependencies: Knockout.js, Backbone.js, and Underscore.js.
-*/(function(){return function(e){return typeof define=="function"&&define.amd?define("knockback-inspector",["underscore","backbone","knockout","knockback"],e):e.call(this)}(function(){var e,t,n,r,i,s={}.hasOwnProperty,o=function(e,t){function r(){this.constructor=e}for(var n in t)s.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e};if(!this._&&typeof require!="undefined")try{i=require("lodash")}catch(u){i=require("underscore")}else i=this._;return i=i.hasOwnProperty("_")?i._:i,e=!this.Backbone&&typeof require!="undefined"?require("backbone"):this.Backbone,r=!this.ko&&typeof require!="undefined"?require("knockout"):this.ko,t=!this.kb&&typeof require!="undefined"?require("knockback"):this.kb,n=this.kbi=typeof exports!="undefined"?exports:{},this.kbi.VERSION="0.1.6",n.TemplateSource=function(){function e(e,t){this.template_generator=e,this.binding_context=t!=null?t:{}}return e.prototype.data=function(e,t){return arguments.length===1?this.binding_context[e]:this.binding_context[e]=t},e.prototype.text=function(){if(arguments.length>0)throw"kbi.TemplateSource: unexpected writing to template source";return this.template_generator.viewText(this.binding_context)},e}(),n.TemplateEngine=function(e){function t(){this.allowTemplateRewriting=!1,this.generators={kbi_array_node:n.ArrayNodeViewGenerator,kbi_model_node:n.ModelNodeViewGenerator,kbi_collection_node:n.CollectionNodeViewGenerator}}return o(t,e),t.prototype.generator=function(e,t){return arguments.length===1?this.generators[e]:this.generators[e]=t},t.prototype.makeTemplateSource=function(e){return this.generators.hasOwnProperty(e)?new n.TemplateSource(new this.generators[e](e)):t.__super__.makeTemplateSource.apply(this,arguments)},t.prototype.renderTemplateSource=function(e,n,r){var i,s;for(i in n)s=n[i],e.data(i,s);return t.__super__.renderTemplateSource.apply(this,arguments)},t}(r.nativeTemplateEngine),n.FetchedModel=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return o(t,e),t.prototype.parse=function(e){var t,r,s,o,u;t={};for(s in e)u=e[s],i.isObject(u)?(o=new n.FetchedModel,t[s]=o.set(o.parse(u))):i.isArray(u)?(r=new n.FetchedCollection,t[s]=r.reset(r.parse(u))):t[s]=u;return t},t}(e.Model),n.FetchedCollection=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return o(t,e),t.prototype.model=n.FetchedModel,t.prototype.parse=function(e){var t;return t=e.results?e.results:e,i.map(e.results,function(e){var t;return t=new n.FetchedModel,t.set(t.parse(e))})},t}(e.Collection),n.NodeViewModel=function(){function e(e,n,s){var o,u;this.name=e,this.node=s,this.opened=r.observable(n),u=r.utils.unwrapObservable(this.node),u instanceof t.ViewModel?(this.node=u,o=t.utils.wrappedModel(this.node),this.attribute_names=r.observableArray(o?i.keys(o.attributes):[])):typeof u.get=="function"&&typeof u.trigger=="function"&&(u.models?this.node=t.collectionObservable(u):(this.node=t.viewModel(u),this.attribute_names=r.observableArray(i.keys(u.attributes))));return}return e}(),n.nodeViewModel=n.nvm=function(e,t,r){return new n.NodeViewModel(e,t,r)},n.ArrayNodeViewGenerator=function(){function e(e){this.template_name=e}return e.prototype.viewText=function(){return""+this.nodeStart()+"\n"+this.nodeManipulator()+"\n <!-- ko if: opened -->\n <!-- ko foreach: node -->\n <!-- ko if: (kb.utils.valueType($data) == kb.TYPE_SIMPLE) -->\n "+this.attributeEditor()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($data) == kb.TYPE_ARRAY) -->\n "+this.arrayTree()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($data) == kb.TYPE_MODEL) -->\n "+this.modelTree()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($data) == kb.TYPE_COLLECTION) -->\n "+this.collectionTree()+"\n <!-- /ko -->\n\n <!-- /ko -->\n <!-- /ko -->\n"+this.nodeEnd()},e.prototype.nodeStart=function(){return"<li class='kbi' data-bind=\"css: {opened: opened, closed: !opened()}\">"},e.prototype.nodeManipulator=function(){return"<div class='array' data-bind=\"click: function(){ opened(!opened()) }\">\n <span data-bind=\"text: (opened() ? '- ' : '+ ' )\"></span>\n <span data-bind=\"text: name + '[]'\"></span>\n</div>"},e.prototype.attributeEditor=function(){return"<fieldset class='kbi'>\n <label data-bind=\"text: '['+$index()+']'\"></label>\n <input type='text' data-bind=\"value: $data, valueUpdate: 'keyup'\">\n</fieldset>"},e.prototype.arrayTree=function(){return""+n.ViewHTML.arrayTree("'['+$index()+']'",!1,"$data")},e.prototype.modelTree=function(){return""+n.ViewHTML.modelTree("'['+$index()+']'",!1,"$data")},e.prototype.collectionTree=function(){return""+n.ViewHTML.collectionTree("'['+$index()+']'",!1,"$data")},e.prototype.nodeEnd=function(){return""},e}(),n.CollectionNodeViewGenerator=function(){function e(e){this.template_name=e}return e.prototype.viewText=function(){return""+this.nodeStart()+"\n"+this.nodeManipulator()+"\n <!-- ko if: opened -->\n <!-- ko foreach: node -->\n "+this.modelNode()+"\n <!-- /ko -->\n <!-- /ko -->\n"+this.nodeEnd()},e.prototype.nodeStart=function(){return"<li class='kbi' data-bind=\"css: {opened: opened, closed: !opened()}\">"},e.prototype.nodeManipulator=function(){return"<div class='collection' data-bind=\"click: function(){ opened(!opened()) }\">\n <span data-bind=\"text: (opened() ? '- ' : '+ ' )\"></span>\n <span data-bind=\"text: name\"></span>\n</div>"},e.prototype.modelNode=function(){return""+n.ViewHTML.modelTree("'['+$index()+']'",!1,"$data")},e.prototype.nodeEnd=function(){return"</li>"},e}(),n.ModelNodeViewGenerator=function(){function e(e){this.template_name=e}return e.prototype.viewText=function(){return""+this.nodeStart()+"\n"+this.nodeManipulator()+"\n <!-- ko if: opened -->\n <!-- ko foreach: attribute_names -->\n <!-- ko if: (kb.utils.valueType($parent.node[$data]) == kb.TYPE_SIMPLE) -->\n "+this.attributeEditor()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($parent.node[$data]) == kb.TYPE_ARRAY) -->\n "+this.arrayTree()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($parent.node[$data]) == kb.TYPE_MODEL) -->\n "+this.modelTree()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($parent.node[$data]) == kb.TYPE_COLLECTION) -->\n "+this.collectionTree()+"\n <!-- /ko -->\n\n <!-- /ko -->\n <!-- /ko -->\n"+this.nodeEnd()},e.prototype.nodeStart=function(){return"<li class='kbi' data-bind=\"css: {opened: opened, closed: !opened()}\">"},e.prototype.nodeManipulator=function(){return"<div class='collection' data-bind=\"click: function(){ opened(!opened()) }\">\n <span data-bind=\"text: (opened() ? '- ' : '+ ' )\"></span>\n <span data-bind=\"text: name\"></span>\n</div>"},e.prototype.attributeEditor=function(){return"<fieldset class='kbi'>\n <label data-bind=\"text: $data\"></label>\n <input type='text' data-bind=\"value: $parent.node[$data], valueUpdate: 'keyup'\">\n</fieldset>"},e.prototype.arrayTree=function(){return""+n.ViewHTML.arrayTree("$data",!1,"$parent.node[$data]")},e.prototype.modelTree=function(){return""+n.ViewHTML.modelTree("$data",!1,"$parent.node[$data]")},e.prototype.collectionTree=function(){return""+n.ViewHTML.collectionTree("$data+'[]'",!0,"$parent.node[$data]")},e.prototype.nodeEnd=function(){return"</li>"},e}(),n.ViewHTML=function(){function e(){}return e.arrayTree=function(e,t,n){return"<ul class='kbi' data-bind=\"template: {name: 'kbi_array_node', data: kbi.nvm("+e+", "+t+", "+n+')}"></ul>'},e.modelTree=function(e,t,n){return"<ul class='kbi' data-bind=\"template: {name: 'kbi_model_node', data: kbi.nvm("+e+", "+t+", "+n+')}"></ul>'},e.collectionTree=function(e,t,n){return"<ul class='kbi' data-bind=\"template: {name: 'kbi_collection_node', data: kbi.nvm("+e+", "+t+", "+n+')}"></ul>'},e}(),n})}).call(this);
+*/(function(){return function(e){return typeof define=="function"&&define.amd?define("knockback-inspector",["underscore","backbone","knockout","knockback"],e):e.call(this)}(function(){var e,t,n,r,i,s={}.hasOwnProperty,o=function(e,t){function r(){this.constructor=e}for(var n in t)s.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e};if(!this._&&typeof require!="undefined")try{i=require("lodash")}catch(u){i=require("underscore")}else i=this._;return i=i.hasOwnProperty("_")?i._:i,e=!this.Backbone&&typeof require!="undefined"?require("backbone"):this.Backbone,r=!this.ko&&typeof require!="undefined"?require("knockout"):this.ko,t=!this.kb&&typeof require!="undefined"?require("knockback"):this.kb,n=this.kbi=typeof exports!="undefined"?exports:{},this.kbi.VERSION="0.1.6",n.TemplateSource=function(){function e(e,t){this.template_generator=e,this.binding_context=t!=null?t:{}}return e.prototype.data=function(e,t){return arguments.length===1?this.binding_context[e]:this.binding_context[e]=t},e.prototype.text=function(){if(arguments.length>0)throw"kbi.TemplateSource: unexpected writing to template source";return this.template_generator.viewText(this.binding_context)},e}(),n.TemplateEngine=function(e){function t(){this.allowTemplateRewriting=!1,this.generators={kbi_array_node:n.ArrayNodeViewGenerator,kbi_model_node:n.ModelNodeViewGenerator,kbi_collection_node:n.CollectionNodeViewGenerator}}return o(t,e),t.prototype.generator=function(e,t){return arguments.length===1?this.generators[e]:this.generators[e]=t},t.prototype.makeTemplateSource=function(e){return this.generators.hasOwnProperty(e)?new n.TemplateSource(new this.generators[e](e)):t.__super__.makeTemplateSource.apply(this,arguments)},t.prototype.renderTemplateSource=function(e,n,r){var i,s;for(i in n)s=n[i],e.data(i,s);return t.__super__.renderTemplateSource.apply(this,arguments)},t}(r.nativeTemplateEngine),n.FetchedModel=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return o(t,e),t.prototype.parse=function(e){var t,r,s,o,u;t={};for(s in e)u=e[s],i.isObject(u)?(o=new n.FetchedModel,t[s]=o.set(o.parse(u))):i.isArray(u)?(r=new n.FetchedCollection,t[s]=r.reset(r.parse(u))):t[s]=u;return t},t}(e.Model),n.FetchedCollection=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return o(t,e),t.prototype.model=n.FetchedModel,t.prototype.parse=function(e){var t;return t=e.results?e.results:e,i.map(e.results,function(e){var t;return t=new n.FetchedModel,t.set(t.parse(e))})},t}(e.Collection),n.NodeViewModel=function(){function e(e,n,s){var o,u;this.name=e,this.node=s,this.opened=r.observable(n),u=r.utils.unwrapObservable(this.node),u instanceof t.ViewModel?(this.node=u,o=t.utils.wrappedModel(this.node),this.attribute_names=r.observableArray(o?i.keys(o.attributes):[])):t.utils.hasCollectionSignature(u)?this.node=t.collectionObservable(u):t.utils.hasModelSignature(u)&&(this.node=t.viewModel(u),this.attribute_names=r.observableArray(i.keys(u.attributes)));return}return e}(),n.nodeViewModel=n.nvm=function(e,t,r){return new n.NodeViewModel(e,t,r)},n.ArrayNodeViewGenerator=function(){function e(e){this.template_name=e}return e.prototype.viewText=function(){return""+this.nodeStart()+"\n"+this.nodeManipulator()+"\n <!-- ko if: opened -->\n <!-- ko foreach: node -->\n <!-- ko if: (kb.utils.valueType($data) == kb.TYPE_SIMPLE) -->\n "+this.attributeEditor()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($data) == kb.TYPE_ARRAY) -->\n "+this.arrayTree()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($data) == kb.TYPE_MODEL) -->\n "+this.modelTree()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($data) == kb.TYPE_COLLECTION) -->\n "+this.collectionTree()+"\n <!-- /ko -->\n\n <!-- /ko -->\n <!-- /ko -->\n"+this.nodeEnd()},e.prototype.nodeStart=function(){return"<li class='kbi' data-bind=\"css: {opened: opened, closed: !opened()}\">"},e.prototype.nodeManipulator=function(){return"<div class='array' data-bind=\"click: function(){ opened(!opened()) }\">\n <span data-bind=\"text: (opened() ? '- ' : '+ ' )\"></span>\n <span data-bind=\"text: name + '[]'\"></span>\n</div>"},e.prototype.attributeEditor=function(){return"<fieldset class='kbi'>\n <label data-bind=\"text: '['+$index()+']'\"></label>\n <input type='text' data-bind=\"value: $data, valueUpdate: 'keyup'\">\n</fieldset>"},e.prototype.arrayTree=function(){return""+n.ViewHTML.arrayTree("'['+$index()+']'",!1,"$data")},e.prototype.modelTree=function(){return""+n.ViewHTML.modelTree("'['+$index()+']'",!1,"$data")},e.prototype.collectionTree=function(){return""+n.ViewHTML.collectionTree("'['+$index()+']'",!1,"$data")},e.prototype.nodeEnd=function(){return""},e}(),n.CollectionNodeViewGenerator=function(){function e(e){this.template_name=e}return e.prototype.viewText=function(){return""+this.nodeStart()+"\n"+this.nodeManipulator()+"\n <!-- ko if: opened -->\n <!-- ko foreach: node -->\n "+this.modelNode()+"\n <!-- /ko -->\n <!-- /ko -->\n"+this.nodeEnd()},e.prototype.nodeStart=function(){return"<li class='kbi' data-bind=\"css: {opened: opened, closed: !opened()}\">"},e.prototype.nodeManipulator=function(){return"<div class='collection' data-bind=\"click: function(){ opened(!opened()) }\">\n <span data-bind=\"text: (opened() ? '- ' : '+ ' )\"></span>\n <span data-bind=\"text: name\"></span>\n</div>"},e.prototype.modelNode=function(){return""+n.ViewHTML.modelTree("'['+$index()+']'",!1,"$data")},e.prototype.nodeEnd=function(){return"</li>"},e}(),n.ModelNodeViewGenerator=function(){function e(e){this.template_name=e}return e.prototype.viewText=function(){return""+this.nodeStart()+"\n"+this.nodeManipulator()+"\n <!-- ko if: opened -->\n <!-- ko foreach: attribute_names -->\n <!-- ko if: (kb.utils.valueType($parent.node[$data]) == kb.TYPE_SIMPLE) -->\n "+this.attributeEditor()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($parent.node[$data]) == kb.TYPE_ARRAY) -->\n "+this.arrayTree()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($parent.node[$data]) == kb.TYPE_MODEL) -->\n "+this.modelTree()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($parent.node[$data]) == kb.TYPE_COLLECTION) -->\n "+this.collectionTree()+"\n <!-- /ko -->\n\n <!-- /ko -->\n <!-- /ko -->\n"+this.nodeEnd()},e.prototype.nodeStart=function(){return"<li class='kbi' data-bind=\"css: {opened: opened, closed: !opened()}\">"},e.prototype.nodeManipulator=function(){return"<div class='collection' data-bind=\"click: function(){ opened(!opened()) }\">\n <span data-bind=\"text: (opened() ? '- ' : '+ ' )\"></span>\n <span data-bind=\"text: name\"></span>\n</div>"},e.prototype.attributeEditor=function(){return"<fieldset class='kbi'>\n <label data-bind=\"text: $data\"></label>\n <input type='text' data-bind=\"value: $parent.node[$data], valueUpdate: 'keyup'\">\n</fieldset>"},e.prototype.arrayTree=function(){return""+n.ViewHTML.arrayTree("$data",!1,"$parent.node[$data]")},e.prototype.modelTree=function(){return""+n.ViewHTML.modelTree("$data",!1,"$parent.node[$data]")},e.prototype.collectionTree=function(){return""+n.ViewHTML.collectionTree("$data+'[]'",!0,"$parent.node[$data]")},e.prototype.nodeEnd=function(){return"</li>"},e}(),n.ViewHTML=function(){function e(){}return e.arrayTree=function(e,t,n){return"<ul class='kbi' data-bind=\"template: {name: 'kbi_array_node', data: kbi.nvm("+e+", "+t+", "+n+')}"></ul>'},e.modelTree=function(e,t,n){return"<ul class='kbi' data-bind=\"template: {name: 'kbi_model_node', data: kbi.nvm("+e+", "+t+", "+n+')}"></ul>'},e.collectionTree=function(e,t,n){return"<ul class='kbi' data-bind=\"template: {name: 'kbi_collection_node', data: kbi.nvm("+e+", "+t+", "+n+')}"></ul>'},e}(),n})}).call(this);
View
2 packages/npm/package.json
@@ -12,7 +12,7 @@
},
"dependencies": {
- "knockback": ">=0.16.6",
+ "knockback": ">=0.16.7",
"backbone-relational": ">=0.5.0",
"backbone-modelref": ">=0.1.5"
},
View
12 packages/nuget/Content/Scripts/knockback-inspector.js
@@ -181,13 +181,11 @@ kbi.NodeViewModel = (function() {
this.node = node_value;
model = kb.utils.wrappedModel(this.node);
this.attribute_names = ko.observableArray(model ? _.keys(model.attributes) : []);
- } else if ((typeof node_value.get === 'function') && (typeof node_value.trigger === 'function')) {
- if (node_value.models) {
- this.node = kb.collectionObservable(node_value);
- } else {
- this.node = kb.viewModel(node_value);
- this.attribute_names = ko.observableArray(_.keys(node_value.attributes));
- }
+ } else if (kb.utils.hasCollectionSignature(node_value)) {
+ this.node = kb.collectionObservable(node_value);
+ } else if (kb.utils.hasModelSignature(node_value)) {
+ this.node = kb.viewModel(node_value);
+ this.attribute_names = ko.observableArray(_.keys(node_value.attributes));
}
return;
}
View
2 packages/nuget/Content/Scripts/knockback-inspector.min.js
@@ -3,4 +3,4 @@
(c) 2011, 2012 Kevin Malakoff - http://kmalakoff.github.com/knockback/
License: MIT (http://www.opensource.org/licenses/mit-license.php)
Dependencies: Knockout.js, Backbone.js, and Underscore.js.
-*/(function(){return function(e){return typeof define=="function"&&define.amd?define("knockback-inspector",["underscore","backbone","knockout","knockback"],e):e.call(this)}(function(){var e,t,n,r,i,s={}.hasOwnProperty,o=function(e,t){function r(){this.constructor=e}for(var n in t)s.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e};if(!this._&&typeof require!="undefined")try{i=require("lodash")}catch(u){i=require("underscore")}else i=this._;return i=i.hasOwnProperty("_")?i._:i,e=!this.Backbone&&typeof require!="undefined"?require("backbone"):this.Backbone,r=!this.ko&&typeof require!="undefined"?require("knockout"):this.ko,t=!this.kb&&typeof require!="undefined"?require("knockback"):this.kb,n=this.kbi=typeof exports!="undefined"?exports:{},this.kbi.VERSION="0.1.6",n.TemplateSource=function(){function e(e,t){this.template_generator=e,this.binding_context=t!=null?t:{}}return e.prototype.data=function(e,t){return arguments.length===1?this.binding_context[e]:this.binding_context[e]=t},e.prototype.text=function(){if(arguments.length>0)throw"kbi.TemplateSource: unexpected writing to template source";return this.template_generator.viewText(this.binding_context)},e}(),n.TemplateEngine=function(e){function t(){this.allowTemplateRewriting=!1,this.generators={kbi_array_node:n.ArrayNodeViewGenerator,kbi_model_node:n.ModelNodeViewGenerator,kbi_collection_node:n.CollectionNodeViewGenerator}}return o(t,e),t.prototype.generator=function(e,t){return arguments.length===1?this.generators[e]:this.generators[e]=t},t.prototype.makeTemplateSource=function(e){return this.generators.hasOwnProperty(e)?new n.TemplateSource(new this.generators[e](e)):t.__super__.makeTemplateSource.apply(this,arguments)},t.prototype.renderTemplateSource=function(e,n,r){var i,s;for(i in n)s=n[i],e.data(i,s);return t.__super__.renderTemplateSource.apply(this,arguments)},t}(r.nativeTemplateEngine),n.FetchedModel=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return o(t,e),t.prototype.parse=function(e){var t,r,s,o,u;t={};for(s in e)u=e[s],i.isObject(u)?(o=new n.FetchedModel,t[s]=o.set(o.parse(u))):i.isArray(u)?(r=new n.FetchedCollection,t[s]=r.reset(r.parse(u))):t[s]=u;return t},t}(e.Model),n.FetchedCollection=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return o(t,e),t.prototype.model=n.FetchedModel,t.prototype.parse=function(e){var t;return t=e.results?e.results:e,i.map(e.results,function(e){var t;return t=new n.FetchedModel,t.set(t.parse(e))})},t}(e.Collection),n.NodeViewModel=function(){function e(e,n,s){var o,u;this.name=e,this.node=s,this.opened=r.observable(n),u=r.utils.unwrapObservable(this.node),u instanceof t.ViewModel?(this.node=u,o=t.utils.wrappedModel(this.node),this.attribute_names=r.observableArray(o?i.keys(o.attributes):[])):typeof u.get=="function"&&typeof u.trigger=="function"&&(u.models?this.node=t.collectionObservable(u):(this.node=t.viewModel(u),this.attribute_names=r.observableArray(i.keys(u.attributes))));return}return e}(),n.nodeViewModel=n.nvm=function(e,t,r){return new n.NodeViewModel(e,t,r)},n.ArrayNodeViewGenerator=function(){function e(e){this.template_name=e}return e.prototype.viewText=function(){return""+this.nodeStart()+"\n"+this.nodeManipulator()+"\n <!-- ko if: opened -->\n <!-- ko foreach: node -->\n <!-- ko if: (kb.utils.valueType($data) == kb.TYPE_SIMPLE) -->\n "+this.attributeEditor()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($data) == kb.TYPE_ARRAY) -->\n "+this.arrayTree()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($data) == kb.TYPE_MODEL) -->\n "+this.modelTree()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($data) == kb.TYPE_COLLECTION) -->\n "+this.collectionTree()+"\n <!-- /ko -->\n\n <!-- /ko -->\n <!-- /ko -->\n"+this.nodeEnd()},e.prototype.nodeStart=function(){return"<li class='kbi' data-bind=\"css: {opened: opened, closed: !opened()}\">"},e.prototype.nodeManipulator=function(){return"<div class='array' data-bind=\"click: function(){ opened(!opened()) }\">\n <span data-bind=\"text: (opened() ? '- ' : '+ ' )\"></span>\n <span data-bind=\"text: name + '[]'\"></span>\n</div>"},e.prototype.attributeEditor=function(){return"<fieldset class='kbi'>\n <label data-bind=\"text: '['+$index()+']'\"></label>\n <input type='text' data-bind=\"value: $data, valueUpdate: 'keyup'\">\n</fieldset>"},e.prototype.arrayTree=function(){return""+n.ViewHTML.arrayTree("'['+$index()+']'",!1,"$data")},e.prototype.modelTree=function(){return""+n.ViewHTML.modelTree("'['+$index()+']'",!1,"$data")},e.prototype.collectionTree=function(){return""+n.ViewHTML.collectionTree("'['+$index()+']'",!1,"$data")},e.prototype.nodeEnd=function(){return""},e}(),n.CollectionNodeViewGenerator=function(){function e(e){this.template_name=e}return e.prototype.viewText=function(){return""+this.nodeStart()+"\n"+this.nodeManipulator()+"\n <!-- ko if: opened -->\n <!-- ko foreach: node -->\n "+this.modelNode()+"\n <!-- /ko -->\n <!-- /ko -->\n"+this.nodeEnd()},e.prototype.nodeStart=function(){return"<li class='kbi' data-bind=\"css: {opened: opened, closed: !opened()}\">"},e.prototype.nodeManipulator=function(){return"<div class='collection' data-bind=\"click: function(){ opened(!opened()) }\">\n <span data-bind=\"text: (opened() ? '- ' : '+ ' )\"></span>\n <span data-bind=\"text: name\"></span>\n</div>"},e.prototype.modelNode=function(){return""+n.ViewHTML.modelTree("'['+$index()+']'",!1,"$data")},e.prototype.nodeEnd=function(){return"</li>"},e}(),n.ModelNodeViewGenerator=function(){function e(e){this.template_name=e}return e.prototype.viewText=function(){return""+this.nodeStart()+"\n"+this.nodeManipulator()+"\n <!-- ko if: opened -->\n <!-- ko foreach: attribute_names -->\n <!-- ko if: (kb.utils.valueType($parent.node[$data]) == kb.TYPE_SIMPLE) -->\n "+this.attributeEditor()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($parent.node[$data]) == kb.TYPE_ARRAY) -->\n "+this.arrayTree()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($parent.node[$data]) == kb.TYPE_MODEL) -->\n "+this.modelTree()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($parent.node[$data]) == kb.TYPE_COLLECTION) -->\n "+this.collectionTree()+"\n <!-- /ko -->\n\n <!-- /ko -->\n <!-- /ko -->\n"+this.nodeEnd()},e.prototype.nodeStart=function(){return"<li class='kbi' data-bind=\"css: {opened: opened, closed: !opened()}\">"},e.prototype.nodeManipulator=function(){return"<div class='collection' data-bind=\"click: function(){ opened(!opened()) }\">\n <span data-bind=\"text: (opened() ? '- ' : '+ ' )\"></span>\n <span data-bind=\"text: name\"></span>\n</div>"},e.prototype.attributeEditor=function(){return"<fieldset class='kbi'>\n <label data-bind=\"text: $data\"></label>\n <input type='text' data-bind=\"value: $parent.node[$data], valueUpdate: 'keyup'\">\n</fieldset>"},e.prototype.arrayTree=function(){return""+n.ViewHTML.arrayTree("$data",!1,"$parent.node[$data]")},e.prototype.modelTree=function(){return""+n.ViewHTML.modelTree("$data",!1,"$parent.node[$data]")},e.prototype.collectionTree=function(){return""+n.ViewHTML.collectionTree("$data+'[]'",!0,"$parent.node[$data]")},e.prototype.nodeEnd=function(){return"</li>"},e}(),n.ViewHTML=function(){function e(){}return e.arrayTree=function(e,t,n){return"<ul class='kbi' data-bind=\"template: {name: 'kbi_array_node', data: kbi.nvm("+e+", "+t+", "+n+')}"></ul>'},e.modelTree=function(e,t,n){return"<ul class='kbi' data-bind=\"template: {name: 'kbi_model_node', data: kbi.nvm("+e+", "+t+", "+n+')}"></ul>'},e.collectionTree=function(e,t,n){return"<ul class='kbi' data-bind=\"template: {name: 'kbi_collection_node', data: kbi.nvm("+e+", "+t+", "+n+')}"></ul>'},e}(),n})}).call(this);
+*/(function(){return function(e){return typeof define=="function"&&define.amd?define("knockback-inspector",["underscore","backbone","knockout","knockback"],e):e.call(this)}(function(){var e,t,n,r,i,s={}.hasOwnProperty,o=function(e,t){function r(){this.constructor=e}for(var n in t)s.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e};if(!this._&&typeof require!="undefined")try{i=require("lodash")}catch(u){i=require("underscore")}else i=this._;return i=i.hasOwnProperty("_")?i._:i,e=!this.Backbone&&typeof require!="undefined"?require("backbone"):this.Backbone,r=!this.ko&&typeof require!="undefined"?require("knockout"):this.ko,t=!this.kb&&typeof require!="undefined"?require("knockback"):this.kb,n=this.kbi=typeof exports!="undefined"?exports:{},this.kbi.VERSION="0.1.6",n.TemplateSource=function(){function e(e,t){this.template_generator=e,this.binding_context=t!=null?t:{}}return e.prototype.data=function(e,t){return arguments.length===1?this.binding_context[e]:this.binding_context[e]=t},e.prototype.text=function(){if(arguments.length>0)throw"kbi.TemplateSource: unexpected writing to template source";return this.template_generator.viewText(this.binding_context)},e}(),n.TemplateEngine=function(e){function t(){this.allowTemplateRewriting=!1,this.generators={kbi_array_node:n.ArrayNodeViewGenerator,kbi_model_node:n.ModelNodeViewGenerator,kbi_collection_node:n.CollectionNodeViewGenerator}}return o(t,e),t.prototype.generator=function(e,t){return arguments.length===1?this.generators[e]:this.generators[e]=t},t.prototype.makeTemplateSource=function(e){return this.generators.hasOwnProperty(e)?new n.TemplateSource(new this.generators[e](e)):t.__super__.makeTemplateSource.apply(this,arguments)},t.prototype.renderTemplateSource=function(e,n,r){var i,s;for(i in n)s=n[i],e.data(i,s);return t.__super__.renderTemplateSource.apply(this,arguments)},t}(r.nativeTemplateEngine),n.FetchedModel=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return o(t,e),t.prototype.parse=function(e){var t,r,s,o,u;t={};for(s in e)u=e[s],i.isObject(u)?(o=new n.FetchedModel,t[s]=o.set(o.parse(u))):i.isArray(u)?(r=new n.FetchedCollection,t[s]=r.reset(r.parse(u))):t[s]=u;return t},t}(e.Model),n.FetchedCollection=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return o(t,e),t.prototype.model=n.FetchedModel,t.prototype.parse=function(e){var t;return t=e.results?e.results:e,i.map(e.results,function(e){var t;return t=new n.FetchedModel,t.set(t.parse(e))})},t}(e.Collection),n.NodeViewModel=function(){function e(e,n,s){var o,u;this.name=e,this.node=s,this.opened=r.observable(n),u=r.utils.unwrapObservable(this.node),u instanceof t.ViewModel?(this.node=u,o=t.utils.wrappedModel(this.node),this.attribute_names=r.observableArray(o?i.keys(o.attributes):[])):t.utils.hasCollectionSignature(u)?this.node=t.collectionObservable(u):t.utils.hasModelSignature(u)&&(this.node=t.viewModel(u),this.attribute_names=r.observableArray(i.keys(u.attributes)));return}return e}(),n.nodeViewModel=n.nvm=function(e,t,r){return new n.NodeViewModel(e,t,r)},n.ArrayNodeViewGenerator=function(){function e(e){this.template_name=e}return e.prototype.viewText=function(){return""+this.nodeStart()+"\n"+this.nodeManipulator()+"\n <!-- ko if: opened -->\n <!-- ko foreach: node -->\n <!-- ko if: (kb.utils.valueType($data) == kb.TYPE_SIMPLE) -->\n "+this.attributeEditor()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($data) == kb.TYPE_ARRAY) -->\n "+this.arrayTree()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($data) == kb.TYPE_MODEL) -->\n "+this.modelTree()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($data) == kb.TYPE_COLLECTION) -->\n "+this.collectionTree()+"\n <!-- /ko -->\n\n <!-- /ko -->\n <!-- /ko -->\n"+this.nodeEnd()},e.prototype.nodeStart=function(){return"<li class='kbi' data-bind=\"css: {opened: opened, closed: !opened()}\">"},e.prototype.nodeManipulator=function(){return"<div class='array' data-bind=\"click: function(){ opened(!opened()) }\">\n <span data-bind=\"text: (opened() ? '- ' : '+ ' )\"></span>\n <span data-bind=\"text: name + '[]'\"></span>\n</div>"},e.prototype.attributeEditor=function(){return"<fieldset class='kbi'>\n <label data-bind=\"text: '['+$index()+']'\"></label>\n <input type='text' data-bind=\"value: $data, valueUpdate: 'keyup'\">\n</fieldset>"},e.prototype.arrayTree=function(){return""+n.ViewHTML.arrayTree("'['+$index()+']'",!1,"$data")},e.prototype.modelTree=function(){return""+n.ViewHTML.modelTree("'['+$index()+']'",!1,"$data")},e.prototype.collectionTree=function(){return""+n.ViewHTML.collectionTree("'['+$index()+']'",!1,"$data")},e.prototype.nodeEnd=function(){return""},e}(),n.CollectionNodeViewGenerator=function(){function e(e){this.template_name=e}return e.prototype.viewText=function(){return""+this.nodeStart()+"\n"+this.nodeManipulator()+"\n <!-- ko if: opened -->\n <!-- ko foreach: node -->\n "+this.modelNode()+"\n <!-- /ko -->\n <!-- /ko -->\n"+this.nodeEnd()},e.prototype.nodeStart=function(){return"<li class='kbi' data-bind=\"css: {opened: opened, closed: !opened()}\">"},e.prototype.nodeManipulator=function(){return"<div class='collection' data-bind=\"click: function(){ opened(!opened()) }\">\n <span data-bind=\"text: (opened() ? '- ' : '+ ' )\"></span>\n <span data-bind=\"text: name\"></span>\n</div>"},e.prototype.modelNode=function(){return""+n.ViewHTML.modelTree("'['+$index()+']'",!1,"$data")},e.prototype.nodeEnd=function(){return"</li>"},e}(),n.ModelNodeViewGenerator=function(){function e(e){this.template_name=e}return e.prototype.viewText=function(){return""+this.nodeStart()+"\n"+this.nodeManipulator()+"\n <!-- ko if: opened -->\n <!-- ko foreach: attribute_names -->\n <!-- ko if: (kb.utils.valueType($parent.node[$data]) == kb.TYPE_SIMPLE) -->\n "+this.attributeEditor()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($parent.node[$data]) == kb.TYPE_ARRAY) -->\n "+this.arrayTree()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($parent.node[$data]) == kb.TYPE_MODEL) -->\n "+this.modelTree()+"\n <!-- /ko -->\n\n <!-- ko if: (kb.utils.valueType($parent.node[$data]) == kb.TYPE_COLLECTION) -->\n "+this.collectionTree()+"\n <!-- /ko -->\n\n <!-- /ko -->\n <!-- /ko -->\n"+this.nodeEnd()},e.prototype.nodeStart=function(){return"<li class='kbi' data-bind=\"css: {opened: opened, closed: !opened()}\">"},e.prototype.nodeManipulator=function(){return"<div class='collection' data-bind=\"click: function(){ opened(!opened()) }\">\n <span data-bind=\"text: (opened() ? '- ' : '+ ' )\"></span>\n <span data-bind=\"text: name\"></span>\n</div>"},e.prototype.attributeEditor=function(){return"<fieldset class='kbi'>\n <label data-bind=\"text: $data\"></label>\n <input type='text' data-bind=\"value: $parent.node[$data], valueUpdate: 'keyup'\">\n</fieldset>"},e.prototype.arrayTree=function(){return""+n.ViewHTML.arrayTree("$data",!1,"$parent.node[$data]")},e.prototype.modelTree=function(){return""+n.ViewHTML.modelTree("$data",!1,"$parent.node[$data]")},e.prototype.collectionTree=function(){return""+n.ViewHTML.collectionTree("$data+'[]'",!0,"$parent.node[$data]")},e.prototype.nodeEnd=function(){return"</li>"},e}(),n.ViewHTML=function(){function e(){}return e.arrayTree=function(e,t,n){return"<ul class='kbi' data-bind=\"template: {name: 'kbi_array_node', data: kbi.nvm("+e+", "+t+", "+n+')}"></ul>'},e.modelTree=function(e,t,n){return"<ul class='kbi' data-bind=\"template: {name: 'kbi_model_node', data: kbi.nvm("+e+", "+t+", "+n+')}"></ul>'},e.collectionTree=function(e,t,n){return"<ul class='kbi' data-bind=\"template: {name: 'kbi_collection_node', data: kbi.nvm("+e+", "+t+", "+n+')}"></ul>'},e}(),n})}).call(this);
View
2 packages/nuget/package.nuspec
@@ -9,7 +9,7 @@
<dependencies>
<dependency id="knockoutjs" version="2.0.0.1" />
<dependency id="Backbone.js" version="0.9.2" />
- <dependency id="Knockback.js" version="0.16.6" />
+ <dependency id="Knockback.js" version="0.16.7" />
</dependencies>
<id>Knockback-Inspector.js</id>
<title>Knockback-Inspector.js</title>
View
17 src/view_models/kbi_node_view_model.coffee
@@ -9,15 +9,14 @@ class kbi.NodeViewModel
model = kb.utils.wrappedModel(@node)
@attribute_names = ko.observableArray(if model then _.keys(model.attributes) else [])
- # Backbone signature
- else if (typeof(node_value.get) is 'function') and (typeof(node_value.trigger) is 'function')
- # Backbone.Collection signature
- if (node_value.models)
- @node = kb.collectionObservable(node_value) # create collection observable
- # Backbone.Model signature
- else
- @node = kb.viewModel(node_value) # create view model
- @attribute_names = ko.observableArray(_.keys(node_value.attributes))
+ # Backbone.Collection signature
+ else if kb.utils.hasCollectionSignature(node_value)
+ @node = kb.collectionObservable(node_value) # create collection observable
+
+ # Backbone.Model signature
+ else if kb.utils.hasModelSignature(node_value)
+ @node = kb.viewModel(node_value) # create view model
+ @attribute_names = ko.observableArray(_.keys(node_value.attributes))
return
View
2 test/core/test-latest-amd.html
@@ -11,7 +11,7 @@
'backbone': "../vendor/backbone-0.9.2",
'backbone-relational': "../vendor/backbone-relational-0.6.0",
'knockout': "../vendor/knockout-2.1.0",
- 'knockback': "../vendor/knockback-core-0.16.6",
+ 'knockback': "../vendor/knockback-core-0.16.7",
'knockback-inspector': "../../knockback-inspector"
}
});
View
2 test/core/test.html
@@ -3,7 +3,7 @@
<head>
<title>Knockback-Inspector Test Suite</title>
<!-- LIBRARY DEPENDENCIES -->
- <script type="text/javascript" src="../../vendor/knockback-core-stack-0.16.6.js"></script>
+ <script type="text/javascript" src="../../vendor/knockback-core-stack-0.16.7.js"></script>
<script type="text/javascript" src="../../vendor/backbone-relational-0.6.0.js"></script>
<!-- LIBRARY -->
View
2 test/core/test.min.html
@@ -3,7 +3,7 @@
<head>
<title>Knockback-Inspector Test Suite (Production)</title>
<!-- LIBRARY DEPENDENCIES -->
- <script type="text/javascript" src='../../vendor/knockback-core-stack-0.16.6.js'></script>
+ <script type="text/javascript" src='../../vendor/knockback-core-stack-0.16.7.js'></script>
<script type="text/javascript" src="../../vendor/backbone-relational-0.6.0.js"></script>
<!-- LIBRARY -->
View
2 test/interactive/index.html
@@ -6,7 +6,7 @@
<!-- DEPENDENCIES -->
<script type="text/javascript" src='../../vendor/jquery-1.8.0.js'></script>
- <script type="text/javascript" src='../../vendor/knockback-core-stack-0.16.6.js'></script>
+ <script type="text/javascript" src='../../vendor/knockback-core-stack-0.16.7.js'></script>
<script type="text/javascript" src="../../vendor/backbone-relational-0.6.0.js"></script>
<!-- KNOCKBACK-INSPECTOR LIBRARY -->
View
655 test/vendor/knockback-core-0.16.6.js → test/vendor/knockback-core-0.16.7.js
@@ -1,5 +1,5 @@
/*
- knockback-core.js 0.16.6
+ knockback-core.js 0.16.7
(c) 2011, 2012 Kevin Malakoff - http://kmalakoff.github.com/knockback/
License: MIT (http://www.opensource.org/licenses/mit-license.php)
Dependencies: Knockout.js, Backbone.js, and Underscore.js.
@@ -16,22 +16,22 @@
}
})(function() {// Generated by CoffeeScript 1.3.3
/*
- knockback-core.js 0.16.6
+ knockback-core.js 0.16.7
(c) 2011, 2012 Kevin Malakoff.
Knockback.js is freely distributable under the MIT license.
See the following for full license details:
https://github.com/kmalakoff/knockback/blob/master/LICENSE
Dependencies: Knockout.js, Backbone.js, and Underscore.js.
*/
-var Backbone, KB_TYPE_ARRAY, KB_TYPE_COLLECTION, KB_TYPE_MODEL, KB_TYPE_SIMPLE, KB_TYPE_UNKNOWN, addStatisticsEvent, arraySplice, buildEvalWithinScopeFunction, collapseOptions, kb, ko, legacyWarning, onReady, throwMissing, throwUnexpected, _, _argumentsAddKey, _unwrapModels, _wrappedKey,
+var Backbone, KB_TYPE_ARRAY, KB_TYPE_COLLECTION, KB_TYPE_MODEL, KB_TYPE_SIMPLE, KB_TYPE_UNKNOWN, addStatisticsEvent, arraySplice, collapseOptions, kb, ko, legacyWarning, onReady, throwMissing, throwUnexpected, _, _argumentsAddKey, _unwrapModels, _wrappedKey,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
kb = (function() {
function kb() {}
- kb.VERSION = '0.16.6';
+ kb.VERSION = '0.16.7';
kb.TYPE_UNKNOWN = 0;
@@ -233,7 +233,8 @@ _unwrapModels = function(obj) {
var key, result, value;
if (!obj) {
return obj;
- } else if (obj.__kb) {
+ }
+ if (obj.__kb) {
if ('object' in obj.__kb) {
return obj.__kb.object;
} else {
@@ -243,16 +244,15 @@ _unwrapModels = function(obj) {
return _.map(obj, function(test) {
return _unwrapModels(test);
});
- } else if (_.isObject(obj) && !ko.isObservable(obj) && !_.isDate(obj) && !_.isString(obj)) {
+ } else if (_.isObject(obj) && (obj.constructor === {}.constructor)) {
result = {};
for (key in obj) {
value = obj[key];
result[key] = _unwrapModels(value);
}
return result;
- } else {
- return obj;
}
+ return obj;
};
kb.utils = (function() {
@@ -292,21 +292,21 @@ kb.utils = (function() {
return _wrappedKey.apply(this, _argumentsAddKey(arguments, 'factory'));
};
- utils.wrappedModelWatcher = function(obj, value) {
- return _wrappedKey.apply(this, _argumentsAddKey(arguments, 'model_watcher'));
+ utils.wrappedEventWatcher = function(obj, value) {
+ return _wrappedKey.apply(this, _argumentsAddKey(arguments, 'event_watcher'));
};
- utils.wrappedModelWatcherIsOwned = function(obj, value) {
- return _wrappedKey.apply(this, _argumentsAddKey(arguments, 'model_watcher_is_owned'));
+ utils.wrappedEventWatcherIsOwned = function(obj, value) {
+ return _wrappedKey.apply(this, _argumentsAddKey(arguments, 'event_watcher_is_owned'));
};
utils.wrappedDestroy = function(obj) {
var __kb;
if (!obj.__kb) {
return;
}
- if (obj.__kb.model_watcher) {
- obj.__kb.model_watcher.releaseCallbacks(obj);
+ if (obj.__kb.event_watcher) {
+ obj.__kb.event_watcher.releaseCallbacks(obj);
}
__kb = obj.__kb;
obj.__kb = null;
@@ -316,10 +316,10 @@ kb.utils = (function() {
__kb.observable = null;
}
__kb.factory = null;
- if (__kb.model_watcher_is_owned) {
- __kb.model_watcher.destroy();
+ if (__kb.event_watcher_is_owned) {
+ __kb.event_watcher.destroy();
}
- __kb.model_watcher = null;
+ __kb.event_watcher = null;
if (__kb.store_is_owned) {
__kb.store.destroy();
}
@@ -401,6 +401,14 @@ kb.utils = (function() {
return ko.observable(obj);
};
+ utils.hasModelSignature = function(obj) {
+ return obj && (obj.attributes && !obj.models) && (typeof obj.get === 'function') && (typeof obj.trigger === 'function');
+ };
+
+ utils.hasCollectionSignature = function(obj) {
+ return obj && obj.models && (typeof obj.get === 'function') && (typeof obj.trigger === 'function');
+ };
+
utils.release = function(obj) {
legacyWarning('kb.utils.release', '0.16.0', 'Please use kb.release instead');
return kb.release(obj);
@@ -536,9 +544,7 @@ kb.Store = (function() {
return;
}
kb.utils.wrappedObject(observable, obj);
- if (!obj) {
- observable.__kb_null = true;
- }
+ obj || (observable.__kb_null = true);
creator = options.creator ? options.creator : (options.path && options.factory ? options.factory.creatorForPath(obj, options.path) : null);
if (!creator) {
creator = observable.constructor;
@@ -651,38 +657,38 @@ kb.Store = (function() {
})();
/*
- knockback_model_watcher.js
+ knockback_event_watcher.js
(c) 2011, 2012 Kevin Malakoff.
Knockback.Observable is freely distributable under the MIT license.
See the following for full license details:
https://github.com/kmalakoff/knockback/blob/master/LICENSE
*/
-addStatisticsEvent = function(model, event_name, info) {
+addStatisticsEvent = function(emitter, event_name, info) {
return !kb.statistics || kb.statistics.addModelEvent({
name: event_name,
- model: model,
+ emitter: emitter,
key: info.key,
path: info.path
});
};
-kb.ModelWatcher = (function() {
+kb.EventWatcher = (function() {
- ModelWatcher.useOptionsOrCreate = function(options, model, obj, callback_options) {
- if (options.model_watcher) {
- if (!(options.model_watcher.model() === model || (options.model_watcher.model_ref === model))) {
- throwUnexpected(this, 'model not matching');
+ EventWatcher.useOptionsOrCreate = function(options, emitter, obj, callback_options) {
+ if (options.event_watcher) {
+ if (!(options.event_watcher.emitter() === emitter || (options.event_watcher.model_ref === emitter))) {
+ throwUnexpected(this, 'emitter not matching');
}
- return kb.utils.wrappedModelWatcher(obj, options.model_watcher).registerCallbacks(obj, callback_options);
+ return kb.utils.wrappedEventWatcher(obj, options.event_watcher).registerCallbacks(obj, callback_options);
} else {
- kb.utils.wrappedModelWatcherIsOwned(obj, true);
- return kb.utils.wrappedModelWatcher(obj, new kb.ModelWatcher(model)).registerCallbacks(obj, callback_options);
+ kb.utils.wrappedEventWatcherIsOwned(obj, true);
+ return kb.utils.wrappedEventWatcher(obj, new kb.EventWatcher(emitter)).registerCallbacks(obj, callback_options);
}
};
- function ModelWatcher(model, obj, callback_options) {
+ function EventWatcher(emitter, obj, callback_options) {
this._onModelUnloaded = __bind(this._onModelUnloaded, this);
this._onModelLoaded = __bind(this._onModelLoaded, this);
@@ -693,62 +699,62 @@ kb.ModelWatcher = (function() {
if (callback_options) {
this.registerCallbacks(obj, callback_options);
}
- if (model) {
- this.model(model);
+ if (emitter) {
+ this.emitter(emitter);
} else {
- this.m = null;
+ this.ee = null;
}
}
- ModelWatcher.prototype.destroy = function() {
- this.model(null);
+ EventWatcher.prototype.destroy = function() {
+ this.emitter(null);
this.__kb.callbacks = null;
return kb.utils.wrappedDestroy(this);
};
- ModelWatcher.prototype.model = function(new_model) {
- var callbacks, event_name, info, list, previous_model, _i, _len, _ref;
- if ((arguments.length === 0) || (this.m === new_model)) {
- return this.m;
+ EventWatcher.prototype.emitter = function(new_emitter) {
+ var callbacks, event_name, info, list, previous_emitter, _i, _len, _ref;
+ if ((arguments.length === 0) || (this.ee === new_emitter)) {
+ return this.ee;
}
if (this.model_ref) {
this.model_ref.unbind('loaded', this.__kb._onModelLoaded);
this.model_ref.unbind('unloaded', this.__kb._onModelUnloaded);
this.model_ref.release();
this.model_ref = null;
}
- if (Backbone.ModelRef && (new_model instanceof Backbone.ModelRef)) {
- this.model_ref = new_model;
+ if (Backbone.ModelRef && (new_emitter instanceof Backbone.ModelRef)) {
+ this.model_ref = new_emitter;
this.model_ref.retain();
this.model_ref.bind('loaded', this.__kb._onModelLoaded);
this.model_ref.bind('unloaded', this.__kb._onModelUnloaded);
- new_model = this.model_ref.model();
+ new_emitter = this.model_ref.model();
} else {
delete this.model_ref;
}
- previous_model = this.m;
- this.m = new_model;
+ previous_emitter = this.ee;
+ this.ee = new_emitter;
_ref = this.__kb.callbacks;
for (event_name in _ref) {
callbacks = _ref[event_name];
- if (previous_model) {
- previous_model.unbind(event_name, callbacks.fn);
+ if (previous_emitter) {
+ previous_emitter.unbind(event_name, callbacks.fn);
}
- if (new_model) {
- new_model.bind(event_name, callbacks.fn);
+ if (new_emitter) {
+ this.ee.bind(event_name, callbacks.fn);
}
list = callbacks.list;
for (_i = 0, _len = list.length; _i < _len; _i++) {
info = list[_i];
- if (info.model) {
- info.model(new_model);
+ if (info.emitter) {
+ info.emitter(this.ee);
}
}
}
- return new_model;
+ return new_emitter;
};
- ModelWatcher.prototype.registerCallbacks = function(obj, callback_info) {
+ EventWatcher.prototype.registerCallbacks = function(obj, callback_info) {
var callbacks, event_name, info, list;
obj || throwMissing(this, 'obj');
callback_info || throwMissing(this, 'info');
@@ -758,39 +764,39 @@ kb.ModelWatcher = (function() {
list = [];
callbacks = {
list: list,
- fn: function(model) {
+ fn: function(emitter) {
var info, _i, _len;
for (_i = 0, _len = list.length; _i < _len; _i++) {
info = list[_i];
if (info.update && !info.rel_fn) {
- if (model && info.key && (model.hasChanged && !model.hasChanged(ko.utils.unwrapObservable(info.key)))) {
+ if (emitter && info.key && (emitter.hasChanged && !emitter.hasChanged(ko.utils.unwrapObservable(info.key)))) {
continue;
}
- !kb.statistics || addStatisticsEvent(model, event_name, info);
+ !kb.statistics || addStatisticsEvent(emitter, event_name, info);
info.update();
}
}
return null;
}
};
this.__kb.callbacks[event_name] = callbacks;
- if (this.m) {
- this.m.bind(event_name, callbacks.fn);
+ if (this.ee) {
+ this.ee.bind(event_name, callbacks.fn);
}
}
info = _.defaults({
obj: obj
}, callback_info);
callbacks.list.push(info);
- if (this.m) {
- if (Backbone.RelationalModel && (this.m instanceof Backbone.RelationalModel)) {
+ if (this.ee) {
+ if (Backbone.RelationalModel && (this.ee instanceof Backbone.RelationalModel)) {
this._modelBindRelatationalInfo(event_name, info);
}
- info.model(this.m) && info.model;
+ info.emitter(this.ee) && info.emitter;
}
};
- ModelWatcher.prototype.releaseCallbacks = function(obj) {
+ EventWatcher.prototype.releaseCallbacks = function(obj) {
var callbacks, event_name, index, info, _ref, _ref1;
if (!this.__kb.callbacks) {
return;
@@ -801,44 +807,45 @@ kb.ModelWatcher = (function() {
_ref1 = callbacks.list;
for (index in _ref1) {
info = _ref1[index];
- if (info.obj === obj) {
- callbacks.list.splice(index, 1);
- if (info.rel_fn) {
- this._modelUnbindRelatationalInfo(event_name, info);
- }
- if (info.model) {
- info.model(null);
- }
- return;
+ if (info.obj !== obj) {
+ continue;
+ }
+ callbacks.list.splice(index, 1);
+ if (info.rel_fn) {
+ this._modelUnbindRelatationalInfo(event_name, info);
}
+ if (info.emitter) {
+ info.emitter(null);
+ }
+ return;
}
}
};
- ModelWatcher.prototype._onModelLoaded = function(model) {
+ EventWatcher.prototype._onModelLoaded = function(model) {
var callbacks, event_name, info, is_relational, list, _i, _len, _ref;
is_relational = Backbone.RelationalModel && (model instanceof Backbone.RelationalModel);
- this.m = model;
+ this.ee = model;
_ref = this.__kb.callbacks;
for (event_name in _ref) {
callbacks = _ref[event_name];
- model.bind(event_name, callbacks.fn);
+ this.ee.bind(event_name, callbacks.fn);
list = callbacks.list;
for (_i = 0, _len = list.length; _i < _len; _i++) {
info = list[_i];
if (is_relational) {
this._modelBindRelatationalInfo(event_name, info);
}
- if (info.model) {
- info.model(model);
+ if (info.emitter) {
+ info.emitter(this.ee);
}
}
}
};
- ModelWatcher.prototype._onModelUnloaded = function(model) {
+ EventWatcher.prototype._onModelUnloaded = function(model) {
var callbacks, event_name, info, list, _i, _len, _ref;
- this.m = null;
+ this.ee = null;
_ref = this.__kb.callbacks;
for (event_name in _ref) {
callbacks = _ref[event_name];
@@ -849,56 +856,56 @@ kb.ModelWatcher = (function() {
if (info.rel_fn) {
this._modelUnbindRelatationalInfo(event_name, info);
}
- if (info.model) {
- info.model(null);
+ if (info.emitter) {
+ info.emitter(null);
}
}
}
};
- ModelWatcher.prototype._modelBindRelatationalInfo = function(event_name, info) {
+ EventWatcher.prototype._modelBindRelatationalInfo = function(event_name, info) {
var key, relation;
if ((event_name === 'change') && info.key && info.update) {
key = ko.utils.unwrapObservable(info.key);
- relation = _.find(this.m.getRelations(), function(test) {
+ relation = _.find(this.ee.getRelations(), function(test) {
return test.key === key;
});
if (!relation) {
return;
}
- info.rel_fn = function(model) {
- !kb.statistics || addStatisticsEvent(model, "" + event_name + " (relational)", info);
+ info.rel_fn = function(emitter) {
+ !kb.statistics || addStatisticsEvent(emitter, "" + event_name + " (relational)", info);
return info.update();
};
if (relation.collectionType || _.isArray(relation.keyContents)) {
info.is_collection = true;
- this.m.bind("add:" + info.key, info.rel_fn);
- this.m.bind("remove:" + info.key, info.rel_fn);
+ this.ee.bind("add:" + info.key, info.rel_fn);
+ this.ee.bind("remove:" + info.key, info.rel_fn);
} else {
- this.m.bind("update:" + info.key, info.rel_fn);
+ this.ee.bind("update:" + info.key, info.rel_fn);
}
}
};
- ModelWatcher.prototype._modelUnbindRelatationalInfo = function(event_name, info) {
+ EventWatcher.prototype._modelUnbindRelatationalInfo = function(event_name, info) {
if (!info.rel_fn) {
return;
}
if (info.is_collection) {
- this.m.unbind("add:" + info.key, info.rel_fn);
- this.m.unbind("remove:" + info.key, info.rel_fn);
+ this.ee.unbind("add:" + info.key, info.rel_fn);
+ this.ee.unbind("remove:" + info.key, info.rel_fn);
} else {
- this.m.unbind("update:" + info.key, info.rel_fn);
+ this.ee.unbind("update:" + info.key, info.rel_fn);
}
info.rel_fn = null;
};
- return ModelWatcher;
+ return EventWatcher;
})();
-kb.modelObservable = function(model, observable) {
- return new kb.ModelWatcher(model, observable);
+kb.emitterObservable = function(emitter, observable) {
+ return new kb.EventWatcher(emitter, observable);
};
/*
@@ -913,7 +920,7 @@ kb.modelObservable = function(model, observable) {
kb.Observable = (function() {
function Observable(model, options, vm) {
- var create_options, model_watcher, observable,
+ var create_options, event_watcher, observable,
_this = this;
this.vm = vm;
options || throwMissing(this, 'options');
@@ -931,9 +938,10 @@ kb.Observable = (function() {
!create_options.args || (this.args = create_options.args, delete create_options.args);
!create_options.read || (this.read = create_options.read, delete create_options.read);
!create_options.write || (this.write = create_options.write, delete create_options.write);
- model_watcher = create_options.model_watcher;
- delete create_options.model_watcher;
+ event_watcher = create_options.event_watcher;
+ delete create_options.event_watcher;
this.vo = ko.observable(null);
+ this._model = ko.observable();
observable = kb.utils.wrappedObservable(this, ko.dependentObservable({
read: function() {
var arg, args, new_value, _i, _len, _ref;
@@ -949,8 +957,8 @@ kb.Observable = (function() {
args.push(ko.utils.unwrapObservable(_this.args));
}
}
- if (_this.m) {
- new_value = _this.read ? _this.read.apply(_this.vm, args) : _this.m.get.apply(_this.m, args);
+ if (_this._mdl === _this._model() && _this._mdl) {
+ new_value = _this.read ? _this.read.apply(_this.vm, args) : _this._mdl.get.apply(_this._mdl, args);
_this.update(new_value);
}
return ko.utils.unwrapObservable(_this.vo());
@@ -972,11 +980,11 @@ kb.Observable = (function() {
args.push(ko.utils.unwrapObservable(_this.args));
}
}
- if (_this.m) {
+ if (_this._mdl) {
if (_this.write) {
_this.write.apply(_this.vm, args);
} else {
- _this.m.set.apply(_this.m, args);
+ _this._mdl.set.apply(_this._mdl, args);
}
}
return _this.update(new_value);
@@ -996,10 +1004,24 @@ kb.Observable = (function() {
observable.value = _.bind(this.value, this);
observable.valueType = _.bind(this.valueType, this);
observable.destroy = _.bind(this.destroy, this);
- kb.ModelWatcher.useOptionsOrCreate({
- model_watcher: model_watcher
+ observable.model = this.model = ko.dependentObservable({
+ read: function() {
+ _this._model();
+ return _this._mdl;
+ },
+ write: function(new_model) {
+ if (_this.__kb_destroyed || (_this._mdl === new_model)) {
+ return;
+ }
+ _this._mdl = new_model;
+ _this.update(null);
+ return _this._model(new_model);
+ }
+ });
+ kb.EventWatcher.useOptionsOrCreate({
+ event_watcher: event_watcher
}, model, this, {
- model: _.bind(this.model, this),
+ emitter: this.model,
update: _.bind(this.update, this),
key: this.key,
path: create_options.path
@@ -1017,11 +1039,13 @@ kb.Observable = (function() {
}
Observable.prototype.destroy = function() {
+ var observable;
+ observable = kb.utils.wrappedObservable(this);
this.__kb_destroyed = true;
kb.release(this.__kb_value);
this.__kb_value = null;
- this.vm = null;
- this.create_options = null;
+ this.model.dispose();
+ observable.model = null;
return kb.utils.wrappedDestroy(this);
};
@@ -1031,29 +1055,18 @@ kb.Observable = (function() {
Observable.prototype.valueType = function() {
var new_value;
- new_value = this.m ? this.m.get(this.key) : null;
+ new_value = this._mdl ? this._mdl.get(this.key) : null;
this.value_type || this._updateValueObservable(new_value);
return this.value_type;
};
- Observable.prototype.model = function(new_model) {
- if (this.__kb_destroyed) {
- return;
- }
- if ((arguments.length === 0) || (this.m === new_model)) {
- return this.m;
- }
- this.m = new_model;
- return this.update();
- };
-
Observable.prototype.update = function(new_value) {
var new_type, value;
if (this.__kb_destroyed) {
return;
}
- if (this.m && !arguments.length) {
- new_value = this.m.get(ko.utils.unwrapObservable(this.key));
+ if (this._mdl && !arguments.length) {
+ new_value = this._mdl.get(ko.utils.unwrapObservable(this.key));
}
(new_value !== void 0) || (new_value = null);
new_type = kb.utils.valueType(new_value);
@@ -1090,7 +1103,7 @@ kb.Observable = (function() {
Observable.prototype._updateValueObservable = function(new_value) {
var create_options, creator, previous_value, value;
create_options = this.create_options;
- create_options.creator = kb.utils.inferCreator(new_value, create_options.factory, create_options.path, this.m, this.key);
+ create_options.creator = kb.utils.inferCreator(new_value, create_options.factory, create_options.path, this._mdl, this.key);
this.value_type = KB_TYPE_UNKNOWN;
creator = create_options.creator;
previous_value = this.__kb_value;
@@ -1158,7 +1171,8 @@ kb.ViewModel = (function() {
ViewModel.extend = Backbone.Model.extend;
function ViewModel(model, options, view_model) {
- var attribute_keys, bb_model, keys, mapped_keys, mapping_info, model_watcher, vm_key, _ref;
+ var attribute_keys, bb_model, event_watcher, keys, mapped_keys, mapping_info, vm_key, _mdl, _ref,
+ _this = this;
!model || (model instanceof Backbone.Model) || ((typeof model.get === 'function') && (typeof model.bind === 'function')) || throwUnexpected(this, 'not a model');
options || (options = {});
view_model || (view_model = {});
@@ -1178,8 +1192,39 @@ kb.ViewModel = (function() {
kb.Store.useOptionsOrCreate(options, model, this);
this.__kb.path = options.path;
kb.Factory.useOptionsOrCreate(options, this, options.path);
- model_watcher = kb.utils.wrappedModelWatcher(this, new kb.ModelWatcher(model, this, {
- model: _.bind(this.model, this)
+ _mdl = _wrappedKey(this, '_mdl', ko.observable());
+ this.model = ko.dependentObservable({
+ read: function() {
+ _mdl();
+ return kb.utils.wrappedObject(_this);
+ },
+ write: function(new_model) {
+ var event_watcher, missing;
+ if (kb.utils.wrappedObject(_this) === new_model) {
+ return;
+ }
+ if (_this.__kb_null) {
+ !new_model || throwUnexpected(_this, 'model set on shared null');
+ return;
+ }
+ kb.utils.wrappedObject(_this, new_model);
+ event_watcher = kb.utils.wrappedEventWatcher(_this);
+ if (!event_watcher) {
+ _mdl(new_model);
+ return;
+ }
+ event_watcher.emitter(new_model);
+ if (!(_this.__kb.keys || !new_model || !new_model.attributes)) {
+ missing = _.difference(_.keys(new_model.attributes), _.keys(_this.__kb.model_keys));
+ if (missing) {
+ _this._createObservables(new_model, missing);
+ }
+ }
+ _mdl(new_model);
+ }
+ });
+ event_watcher = kb.utils.wrappedEventWatcher(this, new kb.EventWatcher(model, this, {
+ emitter: this.model
}));
if (options.requires && _.isArray(options.requires)) {
keys = _.clone(options.requires);
@@ -1201,7 +1246,7 @@ kb.ViewModel = (function() {
this.__kb.keys = _.keys(mapped_keys);
}
} else {
- bb_model = model_watcher.model();
+ bb_model = event_watcher.emitter();
if (bb_model && bb_model.attributes) {
attribute_keys = _.keys(bb_model.attributes);
keys = keys ? _.union(keys, attribute_keys) : attribute_keys;
@@ -1241,38 +1286,13 @@ kb.ViewModel = (function() {
};
};
- ViewModel.prototype.model = function(new_model) {
- var missing, model, model_watcher;
- model = kb.utils.wrappedObject(this);
- if ((arguments.length === 0) || (model === new_model)) {
- return model;
- }
- if (this.__kb_null) {
- !new_model || throwUnexpected(this, 'model set on shared null');
- return;
- }
- kb.utils.wrappedObject(this, new_model);
- model_watcher = kb.utils.wrappedModelWatcher(this);
- if (!model_watcher) {
- return;
- }
- model_watcher.model(new_model);
- if (this.__kb.keys || !new_model || !new_model.attributes) {
- return;
- }
- missing = _.difference(_.keys(new_model.attributes), _.keys(this.__kb.model_keys));
- if (missing) {
- return this._createObservables(new_model, missing);
- }
- };
-
ViewModel.prototype._createObservables = function(model, keys) {
var create_options, key, vm_key, _i, _len;
create_options = {
store: kb.utils.wrappedStore(this),
factory: kb.utils.wrappedFactory(this),
path: this.__kb.path,
- model_watcher: kb.utils.wrappedModelWatcher(this)
+ event_watcher: kb.utils.wrappedEventWatcher(this)
};
for (_i = 0, _len = keys.length; _i < _len; _i++) {
key = keys[_i];
@@ -1293,7 +1313,7 @@ kb.ViewModel = (function() {
store: kb.utils.wrappedStore(this),
factory: kb.utils.wrappedFactory(this),
path: this.__kb.path,
- model_watcher: kb.utils.wrappedModelWatcher(this)
+ event_watcher: kb.utils.wrappedEventWatcher(this)
};
for (vm_key in mappings) {
mapping_info = mappings[vm_key];
@@ -1348,18 +1368,18 @@ kb.CollectionObservable = (function() {
this.__kb._onCollectionChange = _.bind(this._onCollectionChange, this);
options = collapseOptions(options);
if (options.sort_attribute) {
- this.sorted_index_fn = ko.observable(this._sortAttributeFn(options.sort_attribute));
+ this._sorted_index = ko.observable(this._sortAttributeFn(options.sort_attribute));
} else {
if (options.sorted_index) {
legacyWarning(this, '0.16.3', 'use sorted_index_fn instead');
options.sorted_index_fn = options.sorted_index;
}
- this.sorted_index_fn = ko.observable(options.sorted_index_fn);
+ this._sorted_index = ko.observable(options.sorted_index_fn);
}
if (options.filters) {
- this.filters = ko.observableArray(_.isArray(options.filters) ? options.filters : options.filters ? [options.filters] : void 0);
+ this._filters = ko.observableArray(_.isArray(options.filters) ? options.filters : options.filters ? [options.filters] : void 0);
} else {
- this.filters = ko.observableArray([]);
+ this._filters = ko.observableArray([]);
}
create_options = this.create_options = {
store: kb.Store.useOptionsOrCreate(options, collection, observable)
@@ -1373,26 +1393,46 @@ kb.CollectionObservable = (function() {
}
observable.destroy = _.bind(this.destroy, this);
observable.shareOptions = _.bind(this.shareOptions, this);
- observable.collection = _.bind(this.collection, this);
- observable.viewModelByModel = _.bind(this.viewModelByModel, this);
+ observable.filters = _.bind(this.filters, this);
observable.sortedIndex = _.bind(this.sortedIndex, this);
observable.sortAttribute = _.bind(this.sortAttribute, this);
+ observable.viewModelByModel = _.bind(this.viewModelByModel, this);
observable.hasViewModels = _.bind(this.hasViewModels, this);
- this._col = ko.observable();
- this.collection(collection);
+ this._collection = ko.observable(collection);
+ observable.collection = this.collection = ko.dependentObservable({
+ read: function() {
+ return _this._collection();
+ },
+ write: function(new_collection) {
+ var previous_collection;
+ if ((previous_collection = _this._collection()) === new_collection) {
+ return;
+ }
+ if (previous_collection) {
+ previous_collection.unbind('all', _this.__kb._onCollectionChange);
+ }
+ if (new_collection) {
+ new_collection.bind('all', _this.__kb._onCollectionChange);
+ }
+ return _this._collection(new_collection);
+ }
+ });
+ if (collection) {
+ collection.bind('all', this.__kb._onCollectionChange);
+ }
this._mapper = ko.dependentObservable(function() {
- var filters, model, models, sorted_index_fn, view_model, view_models, _i, _len;
+ var current_collection, filters, model, models, sorted_index_fn, view_model, view_models, _i, _len;
if (_this.in_edit) {
return;
}
observable = kb.utils.wrappedObservable(_this);
- collection = _this._col();
- if (collection) {
- models = collection.models;
+ current_collection = _this._collection();
+ if (current_collection) {
+ models = current_collection.models;
}
- sorted_index_fn = _this.sorted_index_fn();
- filters = _this.filters();
- if (!models || (collection.models.length === 0)) {
+ sorted_index_fn = _this._sorted_index();
+ filters = _this._filters();
+ if (!models || (current_collection.models.length === 0)) {
view_models = [];
} else {
if (filters.length) {
@@ -1429,14 +1469,16 @@ kb.CollectionObservable = (function() {
CollectionObservable.prototype.destroy = function() {
var array, collection, observable;
observable = kb.utils.wrappedObservable(this);
- collection = this._col();
+ collection = this._collection();
if (collection) {
collection.unbind('all', this.__kb._onCollectionChange);
array = observable();
array.splice(0, array.length);
}
- kb.release(this.filters);
- this.filters = this._col = this.sorted_index_fn = this._mapper = this.create_options = null;
+ this._mapper.dispose();
+ this.collection.dispose();
+ kb.release(this._filters);
+ observable.collection = null;
kb.utils.wrappedDestroy(this);
return !kb.statistics || kb.statistics.unregister('CollectionObservable', this);
};
@@ -1450,38 +1492,20 @@ kb.CollectionObservable = (function() {
};
};
- CollectionObservable.prototype.collection = function(collection) {
- var observable, previous_collection;
- observable = kb.utils.wrappedObservable(this);
- previous_collection = this._col();
- if ((arguments.length === 0) || (collection === previous_collection)) {
- observable();
- return previous_collection;
- }
- if (previous_collection) {
- previous_collection.unbind('all', this.__kb._onCollectionChange);
- }
- if (collection) {
- collection.bind('all', this.__kb._onCollectionChange);
- }
- this._col(collection);
- return collection;
- };
-
CollectionObservable.prototype.filters = function(filters) {
if (filters) {
- return this.filters(_.isArray(filters) ? filters : [filters]);
+ return this._filters(_.isArray(filters) ? filters : [filters]);
} else {
- return this.filters([]);
+ return this._filters([]);
}
};
CollectionObservable.prototype.sortedIndex = function(sorted_index_fn) {
- return this.sorted_index_fn(sorted_index_fn);
+ return this._sorted_index(sorted_index_fn);
};
CollectionObservable.prototype.sortAttribute = function(sort_attribute) {
- return this.sorted_index_fn(sort_attribute ? this._sortAttributeFn(sort_attribute) : null);
+ return this._sorted_index(sort_attribute ? this._sortAttributeFn(sort_attribute) : null);
};
CollectionObservable.prototype.viewModelByModel = function(model) {
@@ -1547,19 +1571,19 @@ kb.CollectionObservable = (function() {
switch (event) {
case 'reset':
case 'resort':
- if (event === 'resort' && !this.sorted_index_fn()) {
+ if (event === 'resort' && !this._sorted_index()) {
return;
}
- return this._col.notifySubscribers(this._col());
+ return this._collection.notifySubscribers(this._collection());
case 'new':
case 'add':
if (this._modelIsFiltered(arg)) {
return;
}
observable = kb.utils.wrappedObservable(this);
- collection = this._col();
+ collection = this._collection();
view_model = this._createViewModel(arg);
- if ((sorted_index_fn = this.sorted_index_fn())) {
+ if ((sorted_index_fn = this._sorted_index())) {
add_index = sorted_index_fn(observable(), view_model);
} else {
add_index = collection.indexOf(arg);
@@ -1573,7 +1597,7 @@ kb.CollectionObservable = (function() {
case 'change':
if (this._modelIsFiltered(arg)) {
return this._onModelRemove(arg);
- } else if (this.sorted_index_fn()) {
+ } else if (this._sorted_index()) {
return this._onModelResort(arg);
}
}
@@ -1596,12 +1620,12 @@ kb.CollectionObservable = (function() {
observable = kb.utils.wrappedObservable(this);
view_model = this.models_only ? model : this.viewModelByModel(model);
previous_index = observable.indexOf(view_model);
- if ((sorted_index_fn = this.sorted_index_fn())) {
+ if ((sorted_index_fn = this._sorted_index())) {
sorted_view_models = _.clone(observable());
sorted_view_models.splice(previous_index, 1);
new_index = sorted_index_fn(sorted_view_models, view_model);
} else {
- new_index = this._col().indexOf(model);
+ new_index = this._collection().indexOf(model);
}
if (previous_index === new_index) {
return;
@@ -1612,41 +1636,44 @@ kb.CollectionObservable = (function() {
return this.in_edit--;
};
- CollectionObservable.prototype._onObservableArrayChange = function(values) {
- var collection, has_view_model, models, observable, value, _i, _j, _len, _len1,
+ CollectionObservable.prototype._onObservableArrayChange = function(models_or_view_models) {
+ var collection, has_filters, model, models, observable, view_model, view_models, _i, _len,
_this = this;
if (this.in_edit) {
return;
}
+ (this.models_only && (!models_or_view_models.length || kb.utils.hasModelSignature(models_or_view_models[0]))) || (!this.models_only && (!models_or_view_models.length || (_.isObject(models_or_view_models[0]) && !kb.utils.hasModelSignature(models_or_view_models[0])))) || throwUnexpected(this, 'incorrect type passed');
observable = kb.utils.wrappedObservable(this);
- collection = this._col();
- if (!collection) {
+ collection = this._collection();
+ if (!collection || (collection.models === models_or_view_models)) {
return;
}
- if (!this.models_only) {
- for (_i = 0, _len = values.length; _i < _len; _i++) {
- value = values[_i];
- if (value && !(value instanceof Backbone.Model)) {
- has_view_model = true;
- break;
- }
+ has_filters = this._filters().length;
+ view_models = models_or_view_models;
+ if (this.models_only) {
+ if (has_filters) {
+ models = _.filter(models_or_view_models, function(model) {
+ return !_this._modelIsFiltered(model);
+ });
}
- if (has_view_model) {
- for (_j = 0, _len1 = values.length; _j < _len1; _j++) {
- value = values[_j];
- this.create_options.store.findOrReplace(kb.utils.wrappedObject(value), this.create_options.creator, value);
+ } else {
+ !has_filters || (view_models = []);
+ models = [];
+ for (_i = 0, _len = models_or_view_models.length; _i < _len; _i++) {
+ view_model = models_or_view_models[_i];
+ model = kb.utils.wrappedObject(view_model);
+ if (has_filters) {
+ if (this._modelIsFiltered(model)) {
+ continue;
+ }
+ view_models.push(view_model);
}
+ this.create_options.store.findOrReplace(model, this.create_options.creator, view_model);
+ models.push(model);
}
}
- models = _.map(values, function(test) {
- return kb.utils.wrappedModel(test);
- });
- if (this.filters().length) {
- models = _.filter(models, function(model) {
- return !_this._modelIsFiltered(model);
- });
- }
this.in_edit++;
+ (models_or_view_models.length === view_models.length) || observable(view_models);
collection.reset(models);
this.in_edit--;
};
@@ -1681,7 +1708,7 @@ kb.CollectionObservable = (function() {
CollectionObservable.prototype._modelIsFiltered = function(model) {
var filter, filters, _i, _len;
- filters = this.filters();
+ filters = this._filters();
for (_i = 0, _len = filters.length; _i < _len; _i++) {
filter = filters[_i];
filter = ko.utils.unwrapObservable(filter);
@@ -1717,108 +1744,108 @@ kb.sortedIndexWrapAttr = kb.siwa = function(attribute_name, wrapper_constructor)
*/
-buildEvalWithinScopeFunction = function(expression, scopeLevels) {
- var functionBody, i;
- functionBody = "return ( " + expression + " )";
- i = -1;
- while (++i < scopeLevels) {
- functionBody = "with(sc[" + i + "]) { " + functionBody + " }";
- }
- return new Function("sc", functionBody);
-};
-
ko.bindingHandlers['inject'] = {
'init': function(element, value_accessor, all_bindings_accessor, view_model) {
- return kb.inject(ko.utils.unwrapObservable(value_accessor()), view_model, element, value_accessor, all_bindings_accessor);
+ return kb.Inject.inject(ko.utils.unwrapObservable(value_accessor()), view_model, element, value_accessor, all_bindings_accessor);
}
};
-kb.inject = function(data, view_model, element, value_accessor, all_bindings_accessor, nested) {
- var inject, result, wrapper;
- inject = function(data) {
- var key, target, value;
- if (_.isFunction(data)) {
- view_model = new data(view_model, element, value_accessor, all_bindings_accessor);
- kb.releaseOnNodeRemove(view_model, element);
- } else {
- if (data.view_model) {
- view_model = new data.view_model(view_model, element, value_accessor, all_bindings_accessor);
+kb.Inject = (function() {
+
+ function Inject() {}
+
+ Inject.inject = function(data, view_model, element, value_accessor, all_bindings_accessor, nested) {
+ var inject, result, wrapper;
+ inject = function(data) {
+ var key, target, value;
+ if (_.isFunction(data)) {
+ view_model = new data(view_model, element, value_accessor, all_bindings_accessor);
kb.releaseOnNodeRemove(view_model, element);
- }
- for (key in data) {
- value = data[key];
- if (key === 'view_model') {
- continue;
+ } else {
+ if (data.view_model) {
+ view_model = new data.view_model(view_model, element, value_accessor, all_bindings_accessor);
+ kb.releaseOnNodeRemove(view_model, element);
}
- if (key === 'create') {
- value(view_model, element, value_accessor, all_bindings_accessor);
- } else if (_.isObject(value) && !_.isFunction(value)) {
- target = nested || (value && value.create) ? {} : view_model;
- view_model[key] = kb.inject(value, target, element, value_accessor, all_bindings_accessor, true);
- } else {
- view_model[key] = value;
+ for (key in data) {
+ value = data[key];
+ if (key === 'view_model') {
+ continue;
+ }
+ if (key === 'create') {
+ value(view_model, element, value_accessor, all_bindings_accessor);
+ } else if (_.isObject(value) && !_.isFunction(value)) {
+ target = nested || (value && value.create) ? {} : view_model;
+ view_model[key] = kb.Inject.inject(value, target, element, value_accessor, all_bindings_accessor, true);
+ } else {
+ view_model[key] = value;
+ }
}
}
- }
- return view_model;
- };
- if (nested) {
- return inject(data);
- } else {
- result = (wrapper = ko.dependentObservable(function() {
+ return view_model;
+ };
+ if (nested) {
return inject(data);
- }))();
- wrapper.dispose();
- return result;
- }
-};
-
-kb.injectViewModels = function(root) {
- var afterBinding, app, beforeBinding, data, expression, findElements, options, results, _i, _len;
- results = [];
- findElements = function(el) {
- var attr, child_el, _i, _len, _ref;
- if (!el.__kb_injected) {
- if (el.attributes && (attr = _.find(el.attributes, function(attr) {
- return attr.name === 'kb-inject';
- }))) {
- el.__kb_injected = true;
- results.push({
- el: el,
- view_model: {},
- binding: attr.value
- });
+ } else {
+ result = (wrapper = ko.dependentObservable(function() {
+ return inject(data);
+ }))();
+ wrapper.dispose();
+ return result;
+ }
+ };
+
+ Inject.injectViewModels = function(root) {
+ var afterBinding, app, beforeBinding, data, expression, findElements, options, results, _i, _len;
+ results = [];
+ findElements = function(el) {
+ var attr, child_el, _i, _len, _ref;
+ if (!el.__kb_injected) {
+ if (el.attributes && (attr = _.find(el.attributes, function(attr) {
+ return attr.name === 'kb-inject';
+ }))) {
+ el.__kb_injected = true;
+ results.push({
+ el: el,
+ view_model: {},
+ binding: attr.value
+ });
+ }
+ }
+ _ref = el.childNodes;
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ child_el = _ref[_i];
+ findElements(child_el);
+ }
+ };
+ findElements(root || document);
+ for (_i = 0, _len = results.length; _i < _len; _i++) {
+ app = results[_i];
+ if (expression = app.binding) {
+ (expression.search(/[:]/) < 0) || (expression = "{" + expression + "}");
+ data = (new Function("", "return ( " + expression + " )"))();
+ data || (data = {});
+ (!data.options) || (options = data.options, delete data.options);
+ options || (options = {});
+ app.view_model = kb.Inject.inject(data, app.view_model, app.el, null, null, true);
+ afterBinding = app.view_model.afterBinding || options.afterBinding;
+ beforeBinding = app.view_model.beforeBinding || options.beforeBinding;
+ }
+ if (beforeBinding) {
+ beforeBinding(app.view_model, app.el, options);
+ }
+ kb.applyBindings(app.view_model, app.el, options);
+ if (afterBinding) {
+ afterBinding(app.view_model, app.el, options);
}
}
- _ref = el.childNodes;
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- child_el = _ref[_i];
- findElements(child_el);
- }
- };
- findElements(root || document);
- for (_i = 0, _len = results.length; _i < _len; _i++) {
- app = results[_i];
- if (expression = app.binding) {
- (expression.search(/[:]/) < 0) || (expression = "{" + expression + "}");
- data = buildEvalWithinScopeFunction(expression, 0)();
- data || (data = {});
- (!data.options) || (options = data.options, delete data.options);
- options || (options = {});
- app.view_model = kb.inject(data, app.view_model, app.el, null, null, true);
- afterBinding = app.view_model.afterBinding || options.afterBinding;
- beforeBinding = app.view_model.beforeBinding || options.beforeBinding;
- }
- if (beforeBinding) {
- beforeBinding(app.view_model, app.el, options);
- }
- kb.applyBindings(app.view_model, app.el, options);
- if (afterBinding) {
- afterBinding(app.view_model, app.el, options);
- }
- }
- return results;
-};
+ return results;
+ };
+
+ return Inject;
+
+})();
+
+kb.injectViewModels = kb.Inject.injectViewModels;
if (this.$) {
this.$(function() {
View
2 tutorials/coffeescript/step1/index.html
@@ -6,7 +6,7 @@
<!-- DEPENDENCIES -->
<script type="text/javascript" src='../../../vendor/jquery-1.8.0.js'></script>
- <script type="text/javascript" src='../../../vendor/knockback-core-stack-0.16.6.js'></script>
+ <script type="text/javascript" src='../../../vendor/knockback-core-stack-0.16.7.js'></script>
<script type="text/javascript" src="../../../vendor/backbone-relational-0.6.0.js"></script>
<!-- KNOCKBACK-INSPECTOR LIBRARY -->
View
2 tutorials/coffeescript/step2/index.html
@@ -6,7 +6,7 @@
<!-- DEPENDENCIES -->
<script type="text/javascript" src='../../../vendor/jquery-1.8.0.js'></script>
- <script type="text/javascript" src='../../../vendor/knockback-core-stack-0.16.6.js'></script>
+ <script type="text/javascript" src='../../../vendor/knockback-core-stack-0.16.7.js'></script>
<script type="text/javascript" src="../../../vendor/backbone-relational-0.6.0.js"></script>
<!-- KNOCKBACK-INSPECTOR LIBRARY -->
View
2 tutorials/coffeescript/step3/index.html
@@ -6,7 +6,7 @@
<!-- DEPENDENCIES -->
<script type="text/javascript" src='../../../vendor/jquery-1.8.0.js'></script>
- <script type="text/javascript" src='../../../vendor/knockback-core-stack-0.16.6.js'></script>
+ <script type="text/javascript" src='../../../vendor/knockback-core-stack-0.16.7.js'></script>
<script type="text/javascript" src="../../../vendor/backbone-relational-0.6.0.js"></script>
<!-- KNOCKBACK-INSPECTOR LIBRARY -->
View
2 tutorials/coffeescript/step4/index.html
@@ -6,7 +6,7 @@
<!-- DEPENDENCIES -->
<script type="text/javascript" src='../../../vendor/jquery-1.8.0.js'></script>
- <script type="text/javascript" src='../../../vendor/knockback-core-stack-0.16.6.js'></script>
+ <script type="text/javascript" src='../../../vendor/knockback-core-stack-0.16.7.js'></script>
<script type="text/javascript" src="../../../vendor/backbone-relational-0.6.0.js"></script>
<!-- KNOCKBACK-INSPECTOR LIBRARY -->
View
2 tutorials/javascript/step1/index.html
@@ -6,7 +6,7 @@
<!-- DEPENDENCIES -->
<script type="text/javascript" src='../../../vendor/jquery-1.8.0.js'></script>
- <script type="text/javascript" src='../../../vendor/knockback-core-stack-0.16.6.js'></script>
+ <script type="text/javascript" src='../../../vendor/knockback-core-stack-0.16.7.js'></script>
<script type="text/javascript" src="../../../vendor/backbone-relational-0.6.0.js"></script>
<!-- KNOCKBACK-INSPECTOR LIBRARY -->
View
2 tutorials/javascript/step2/index.html
@@ -6,7 +6,7 @@
<!-- DEPENDENCIES -->
<script type="text/javascript" src='../../../vendor/jquery-1.8.0.js'></script>
- <script type="text/javascript" src='../../../vendor/knockback-core-stack-0.16.6.js'></script>
+ <script type="text/javascript" src='../../../vendor/knockback-core-stack-0.16.7.js'></script>
<script type="text/javascript" src="../../../vendor/backbone-relational-0.6.0.js"></script>
<!-- KNOCKBACK-INSPECTOR LIBRARY -->
View
2 tutorials/javascript/step3/index.html
@@ -6,7 +6,7 @@
<!-- DEPENDENCIES -->
<script type="text/javascript" src='../../../vendor/jquery-1.8.0.js'></script>
- <script type="text/javascript" src='../../../vendor/knockback-core-stack-0.16.6.js'></script>
+ <script type="text/javascript" src='../../../vendor/knockback-core-stack-0.16.7.js'></script>
<script type="text/javascript" src="../../../vendor/backbone-relational-0.6.0.js"></script>
<!-- KNOCKBACK-INSPECTOR LIBRARY -->
View
2 tutorials/javascript/step4/index.html
@@ -6,7 +6,7 @@
<!-- DEPENDENCIES -->
<script type="text/javascript" src='../../../vendor/jquery-1.8.0.js'></script>
- <script type="text/javascript" src='../../../vendor/knockback-core-stack-0.16.6.js'></script>
+ <script type="text/javascript" src='../../../vendor/knockback-core-stack-0.16.7.js'></script>
<script type="text/javascript" src="../../../vendor/backbone-relational-0.6.0.js"></script>
<!-- KNOCKBACK-INSPECTOR LIBRARY -->
View
655 vendor/knockback-core-stack-0.16.6.js → vendor/knockback-core-stack-0.16.7.js
@@ -1,5 +1,5 @@
/*
- knockback-core-stack.js 0.16.6
+ knockback-core-stack.js 0.16.7
(c) 2011, 2012 Kevin Malakoff - http://kmalakoff.github.com/knockback/
License: MIT (http://www.opensource.org/licenses/mit-license.php)
Dependencies: Knockout.js, Backbone.js, and Underscore.js.
@@ -5938,7 +5938,7 @@ ko.exportSymbol('nativeTemplateEngine', ko.nativeTemplateEngine);
});
})(window,document,navigator);
/*
- knockback-core.js 0.16.6
+ knockback-core.js 0.16.7
(c) 2011, 2012 Kevin Malakoff - http://kmalakoff.github.com/knockback/
License: MIT (http://www.opensource.org/licenses/mit-license.php)
Dependencies: Knockout.js, Backbone.js, and Underscore.js.
@@ -5955,22 +5955,22 @@ ko.exportSymbol('nativeTemplateEngine', ko.nativeTemplateEngine);
}
})(function() {// Generated by CoffeeScript 1.3.3
/*
- knockback-core.js 0.16.6
+ knockback-core.js 0.16.7
(c) 2011, 2012 Kevin Malakoff.
Knockback.js is freely distributable under the MIT license.
See the following for full license details:
https://github.com/kmalakoff/knockback/blob/master/LICENSE
Dependencies: Knockout.js, Backbone.js, and Underscore.js.
*/
-var Backbone, KB_TYPE_ARRAY, KB_TYPE_COLLECTION, KB_TYPE_MODEL, KB_TYPE_SIMPLE, KB_TYPE_UNKNOWN, addStatisticsEvent, arraySplice, buildEvalWithinScopeFunction, collapseOptions, kb, ko, legacyWarning, onReady, throwMissing, throwUnexpected, _, _argumentsAddKey, _unwrapModels, _wrappedKey,
+var Backbone, KB_TYPE_ARRAY, KB_TYPE_COLLECTION, KB_TYPE_MODEL, KB_TYPE_SIMPLE, KB_TYPE_UNKNOWN, addStatisticsEvent, arraySplice, collapseOptions, kb, ko, legacyWarning, onReady, throwMissing, throwUnexpected, _, _argumentsAddKey, _unwrapModels, _wrappedKey,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
kb = (function() {
function kb() {}
- kb.VERSION = '0.16.6';
+ kb.VERSION = '0.16.7';
kb.TYPE_UNKNOWN = 0;
@@ -6172,7 +6172,8 @@ _unwrapModels = function(obj) {
var key, result, value;
if (!obj) {
return obj;
- } else if (obj.__kb) {
+ }
+ if (obj.__kb) {
if ('object' in obj.__kb) {
return obj.__kb.object;
} else {
@@ -6182,16 +6183,15 @@ _unwrapModels = function(obj) {
return _.map(obj, function(test) {
return _unwrapModels(test);
});
- } else if (_.isObject(obj) && !ko.isObservable(obj) && !_.isDate(obj) && !_.isString(obj)) {
+ } else if (_.isObject(obj) && (obj.constructor === {}.constructor)) {
result = {};
for (key in obj) {
value = obj[key];
result[key] = _unwrapModels(value);
}
return result;
- } else {
- return obj;
}
+ return obj;
};
kb.utils = (function() {
@@ -6231,21 +6231,21 @@ kb.utils = (function() {
return _wrappedKey.apply(this, _argumentsAddKey(arguments, 'factory'));
};
- utils.wrappedModelWatcher = function(obj, value) {
- return _wrappedKey.apply(this, _argumentsAddKey(arguments, 'model_watcher'));
+ utils.wrappedEventWatcher = function(obj, value) {
+ return _wrappedKey.apply(this, _argumentsAddKey(arguments, 'event_watcher'));
};
- utils.wrappedModelWatcherIsOwned = function(obj, value) {
- return _wrappedKey.apply(this, _argumentsAddKey(arguments, 'model_watcher_is_owned'));
+ utils.wrappedEventWatcherIsOwned = function(obj, value) {
+ return _wrappedKey.apply(this, _argumentsAddKey(arguments, 'event_watcher_is_owned'));
};
utils.wrappedDestroy = function(obj) {
var __kb;
if (!obj.__kb) {
return;
}
- if (obj.__kb.model_watcher) {
- obj.__kb.model_watcher.releaseCallbacks(obj);
+ if (obj.__kb.event_watcher) {
+ obj.__kb.event_watcher.releaseCallbacks(obj);
}
__kb = obj.__kb;
obj.__kb = null;
@@ -6255,10 +6255,10 @@ kb.utils = (function() {
__kb.observable = null;
}
__kb.factory = null;
- if (__kb.model_watcher_is_owned) {
- __kb.model_watcher.destroy();
+ if (__kb.event_watcher_is_owned) {
+ __kb.event_watcher.destroy();
}
- __kb.model_watcher = null;
+ __kb.event_watcher = null;
if (__kb.store_is_owned) {
__kb.store.destroy();
}
@@ -6340,6 +6340,14 @@ kb.utils = (function() {
return ko.observable(obj);
};
+ utils.hasModelSignature = function(obj) {
+ return obj && (obj.attributes && !obj.models) && (typeof obj.get === 'function') && (typeof obj.trigger === 'function');
+ };
+
+ utils.hasCollectionSignature = function(obj) {
+ return obj && obj.models && (typeof obj.get === 'function') && (typeof obj.trigger === 'function');
+ };
+
utils.release = function(obj) {
legacyWarning('kb.utils.release', '0.16.0', 'Please use kb.release instead');
return kb.release(obj);
@@ -6475,9 +6483,7 @@ kb.Store = (function() {
return;
}
kb.utils.wrappedObject(observable, obj);
- if (!obj) {
- observable.__kb_null = true;
- }
+ obj || (observable.__kb_null = true);
creator = options.creator ? options.creator : (options.path && options.factory ? options.factory.creatorForPath(obj, options.path) : null);
if (!creator) {
creator = observable.constructor;
@@ -6590,38 +6596,38 @@ kb.Store = (function() {
})();
/*
- knockback_model_watcher.js
+ knockback_event_watcher.js
(c) 2011, 2012 Kevin Malakoff.
Knockback.Observable is freely distributable under the MIT license.
See the following for full license details:
https://github.com/kmalakoff/knockback/blob/master/LICENSE
*/
-addStatisticsEvent = function(model, event_name, info) {
+addStatisticsEvent = function(emitter, event_name, info) {
return !kb.statistics || kb.statistics.addModelEvent({
name: event_name,
- model: model,
+ emitter: emitter,
key: info.key,
path: info.path
});
};
-kb.ModelWatcher = (function() {
+kb.EventWatcher = (function() {
- ModelWatcher.useOptionsOrCreate = function(options, model, obj, callback_options) {
- if (options.model_watcher) {
- if (!(options.model_watcher.model() === model || (options.model_watcher.model_ref === model))) {
- throwUnexpected(this, 'model not matching');
+ EventWatcher.useOptionsOrCreate = function(options, emitter, obj, callback_options) {
+ if (options.event_watcher) {
+ if (!(options.event_watcher.emitter() === emitter || (options.event_watcher.model_ref === emitter))) {
+ throwUnexpected(this, 'emitter not matching');
}
- return kb.utils.wrappedModelWatcher(obj, options.model_watcher).registerCallbacks(obj, callback_options);
+ return kb.utils.wrappedEventWatcher(obj, options.event_watcher).registerCallbacks(obj, callback_options);
} else {
- kb.utils.wrappedModelWatcherIsOwned(obj, true);
- return kb.utils.wrappedModelWatcher(obj, new kb.ModelWatcher(model)).registerCallbacks(obj, callback_options);
+ kb.utils.wrappedEventWatcherIsOwned(obj, true);
+ return kb.utils.wrappedEventWatcher(obj, new kb.EventWatcher(emitter)).registerCallbacks(obj, callback_options);
}
};
- function ModelWatcher(model, obj, callback_options) {
+ function EventWatcher(emitter, obj, callback_options) {
this._onModelUnloaded = __bind(this._onModelUnloaded, this);
this._onModelLoaded = __bind(this._onModelLoaded, this);
@@ -6632,62 +6638,62 @@ kb.ModelWatcher = (function() {
if (callback_options) {
this.registerCallbacks(obj, callback_options);
}
- if (model) {
- this.model(model);
+ if (emitter) {
+ this.emitter(emitter);
} else {
- this.m = null;
+ this.ee = null;
}
}
- ModelWatcher.prototype.destroy = function() {
- this.model(null);
+ EventWatcher.prototype.destroy = function() {
+ this.emitter(null);
this.__kb.callbacks = null;
return kb.utils.wrappedDestroy(this);
};
- ModelWatcher.prototype.model = function(new_model) {
- var callbacks, event_name, info, list, previous_model, _i, _len, _ref;
- if ((arguments.length === 0) || (this.m === new_model)) {
- return this.m;
+ EventWatcher.prototype.emitter = function(new_emitter) {
+ var callbacks, event_name, info, list, previous_emitter, _i, _len, _ref;
+ if ((arguments.length === 0) || (this.ee === new_emitter)) {
+ return this.ee;
}
if (this.model_ref) {
this.model_ref.unbind('loaded', this.__kb._onModelLoaded);
this.model_ref.unbind('unloaded', this.__kb._onModelUnloaded);
this.model_ref.release();
this.model_ref = null;
}
- if (Backbone.ModelRef && (new_model instanceof Backbone.ModelRef)) {
- this.model_ref = new_model;
+ if (Backbone.ModelRef && (new_emitter instanceof Backbone.ModelRef)) {
+ this.model_ref = new_emitter;
this.model_ref.retain();
this.model_ref.bind('loaded', this.__kb._onModelLoaded);
this.model_ref.bind('unloaded', this.__kb._onModelUnloaded);
- new_model = this.model_ref.model();
+ new_emitter = this.model_ref.model();
} else {
delete this.model_ref;
}
- previous_model = this.m;
- this.m = new_model;
+ previous_emitter = this.ee;
+ this.ee = new_emitter;
_ref = this.__kb.callbacks;
for (event_name in _ref) {
callbacks = _ref[event_name];
- if (previous_model) {
- previous_model.unbind(event_name, callbacks.fn);
+ if (previous_emitter) {
+ previous_emitter.unbind(event_name, callbacks.fn);
}
- if (new_model) {
- new_model.bind(event_name, callbacks.fn);