From 0811df6419b34cbda4dd9edc77e6321ba50c65ce Mon Sep 17 00:00:00 2001 From: Ben Olson Date: Sun, 8 Dec 2013 14:30:56 -0500 Subject: [PATCH] Build v0.1.4 --- backbone-fiber.js | 16 +++++++++++++++- backbone-fiber.min.js | 2 +- bower.json | 2 +- package.json | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/backbone-fiber.js b/backbone-fiber.js index dab710e..974d4d0 100644 --- a/backbone-fiber.js +++ b/backbone-fiber.js @@ -422,12 +422,26 @@ return {}; }, + /** + * Default logic to unset data and allow for an event to trigger + */ + + clearData: function() { + var dm = this.data(); + this.unbindData(); + this.model = null; + this.collection = null; + this.trigger('undata', dm ); + return this; + + }, + /** * Default logic to set data on the view. Takes a hash with either model or collection set to the new data value. * Any custom functions must ensure they properly bind and unbind data. The trigger is optional. * Returns itself for chaining. */ - + setData: function( data ) { var dm = null; diff --git a/backbone-fiber.min.js b/backbone-fiber.min.js index 89a7995..82f35c5 100644 --- a/backbone-fiber.min.js +++ b/backbone-fiber.min.js @@ -1 +1 @@ -(function(t,e){"function"==typeof define&&define.amd?define(["jquery","underscore","backbone","base"],e):t.Backbone.Fiber=e(t.$,t._,t.Backbone,Base)})(this,function(t,e,i,n){function r(i){var n=t.Deferred();return s[i]?n.resolve(s[i]):(h[i]=n,require([d.viewPath+i,"text!"+d.viewPath+i+".html"],function(t,r){t.prototype.instanceOf=i,t.prototype.template=e.template(r),s[i]=t,delete h[i],n.resolve(t)})),n.promise()}function o(t,i,n){var r,o=new t(e.extend(n,{el:i[0]})),a=!1;return i.attr("data-cid",o.cid),c[o.cid]=o,r=i.parents("[data-view]").first(),r.length>0&&(r=r.attr("data-cid"),c[r]?(c[r].addChild(o),o.setParent(c[r])):(a=!0,o.remove())),a||o.render(),o}function a(e,i){var n=i||{},a=e instanceof t?e:t(e),d=a.attr("data-view");d&&r(d).done(function(t){o(t,a,n)})}i.View.extend=n.extend,i.View.mix=n.mix;var d,s={},c={},h={},l=t.cleanData;return t.cleanData=function(e){for(var i,n=0;void 0!==(i=e[n]);n++)t(i).triggerHandler("destroyed");l(e)},i.Fiber=d={viewPath:"views/",getViewFromEl:function(e){var i=t(e),n=i.attr("data-cid")||i.closest("[data-cid]").attr("data-cid");return n?c[n]:void 0},getViewFromCid:function(t){return c[t]},getElFromCid:function(t){return c[t]?c[t].$el:void 0},getPromise:function(t){return h[t]?h[t]:void 0}},d.start=function(){a(document.body)},i.View.mix([{template:null,parent:null,children:null,renderedOnce:!1,forceRender:!1,connect:function(e,i){var n,r,o=this,s=t.Deferred();return n="string"==typeof e?this.factory(e):e instanceof t?e:t(e),a(n,i),(r=d.getPromise(n.attr("data-view")))?r.done(function(){s.resolveWith(o,[d.getViewFromEl(n)])}):s.resolveWith(this,[d.getViewFromEl(n)]),s.promise()},waitFor:function(i,n){var r=this,o=e.compact(e.map(i,function(t){return d.getPromise(t)}));t.when.apply(this,o).done(function(){n.apply(r,arguments)})},factory:function(e){return t("
").attr("data-view",e).appendTo(this.$el)},initialize:function(t){this.$el.on("destroyed",e.bind(this.remove,this)),this.options=t||{},this.children=[],this.setup(t),this.bindData(),this.trigger("created")},unbindData:function(){var t=this.data();t.trigger&&this.stopListening(t)},bindData:function(){var i=this,n=this.data();n.trigger&&e.each(this.events,function(e,r){var o;(o=r.indexOf(".data"))>-1&&(e=t.isFunction(e)?e:i[e],i.listenTo(n,r.slice(0,o),e))})},setup:t.noop,render:function(){var e,i;this.beforeRender()!==!1&&(this.trigger("rendering"),this.template&&"function"==typeof this.template&&(e=this.dataSerialized(),i=e&&t.isArray(e),((this.forceRender||this.renderedOnce)&&e||!this.renderedOnce&&(i&&e.length>0||!i))&&(this.$el.empty().html(this.template(e)),this.renderedOnce=!0,this.$el.find("[data-view]").each(function(){a(this)}))),this.afterRender(),this.trigger("rendered"))},beforeRender:t.noop,afterRender:t.noop,data:function(){return this.model?this.model:this.collection?this.collection:{}},setData:function(t){var e=null;return this.unbindData(),t.model?this.model=e=t.model:t.collection&&(this.collection=e=t.collection),this.bindData(),e&&e.trigger&&e.trigger("ready",e,this),this},dataSerialized:function(){var t=this.data();return t.toJSON?t.toJSON({computedFields:!0}):t},remove:function(){this.parent?c[this.parent].removeChild(this):(this.destroy(),this.trigger("removed"),this.stopListening(),this.$el.off("destroyed"),this.$el.remove(),delete c[this.cid]),this._superStop()},destroy:t.noop,trigger:function(t,e){this.$el.trigger(t,{view:this,data:e||{}})||this._superStop()},setParent:function(t){this.parent=null,t&&(this.parent=t.cid)},addChild:function(t){e.contains(t.cid,this.children)||this.children.push(t.cid)},removeChild:function(t){var i=e.indexOf(this.children,t.cid);i>-1&&(this.children.splice(i,1),t.setParent(null),t.remove())},allChildren:function(){return e.map(this.children,function(t){return d.getViewFromCid(t)})},findChildren:function(t){return e.compact(e.map(this.children,function(e){var i;return(i=d.getViewFromCid(e))&&i.instanceOf==t?i:void 0}))},findChild:function(e){var i=null;if(e instanceof t)i=d.getViewFromEl(e);else if("string"==typeof e&&(i=d.getViewFromCid(e),!i))for(var n=0;this.children.length>n;n++){var r;(r=d.getViewFromCid(this.children[n]))&&r.instanceOf==e&&(i=r)}return i},isMyElement:function(e){var i=e instanceof t?e:t(e);return i.parents("[data-view]").first().attr("data-cid")==this.cid}}]),d}); \ No newline at end of file +(function(t,e){"function"==typeof define&&define.amd?define(["jquery","underscore","backbone","base"],e):t.Backbone.Fiber=e(t.$,t._,t.Backbone,Base)})(this,function(t,e,i,n){function r(i){var n=t.Deferred();return s[i]?n.resolve(s[i]):(h[i]=n,require([d.viewPath+i,"text!"+d.viewPath+i+".html"],function(t,r){t.prototype.instanceOf=i,t.prototype.template=e.template(r),s[i]=t,delete h[i],n.resolve(t)})),n.promise()}function a(t,i,n){var r,a=new t(e.extend(n,{el:i[0]})),o=!1;return i.attr("data-cid",a.cid),c[a.cid]=a,r=i.parents("[data-view]").first(),r.length>0&&(r=r.attr("data-cid"),c[r]?(c[r].addChild(a),a.setParent(c[r])):(o=!0,a.remove())),o||a.render(),a}function o(e,i){var n=i||{},o=e instanceof t?e:t(e),d=o.attr("data-view");d&&r(d).done(function(t){a(t,o,n)})}i.View.extend=n.extend,i.View.mix=n.mix;var d,s={},c={},h={},l=t.cleanData;return t.cleanData=function(e){for(var i,n=0;void 0!==(i=e[n]);n++)t(i).triggerHandler("destroyed");l(e)},i.Fiber=d={viewPath:"views/",getViewFromEl:function(e){var i=t(e),n=i.attr("data-cid")||i.closest("[data-cid]").attr("data-cid");return n?c[n]:void 0},getViewFromCid:function(t){return c[t]},getElFromCid:function(t){return c[t]?c[t].$el:void 0},getPromise:function(t){return h[t]?h[t]:void 0}},d.start=function(){o(document.body)},i.View.mix([{template:null,parent:null,children:null,renderedOnce:!1,forceRender:!1,connect:function(e,i){var n,r,a=this,s=t.Deferred();return n="string"==typeof e?this.factory(e):e instanceof t?e:t(e),o(n,i),(r=d.getPromise(n.attr("data-view")))?r.done(function(){s.resolveWith(a,[d.getViewFromEl(n)])}):s.resolveWith(this,[d.getViewFromEl(n)]),s.promise()},waitFor:function(i,n){var r=this,a=e.compact(e.map(i,function(t){return d.getPromise(t)}));t.when.apply(this,a).done(function(){n.apply(r,arguments)})},factory:function(e){return t("
").attr("data-view",e).appendTo(this.$el)},initialize:function(t){this.$el.on("destroyed",e.bind(this.remove,this)),this.options=t||{},this.children=[],this.setup(t),this.bindData(),this.trigger("created")},unbindData:function(){var t=this.data();t.trigger&&this.stopListening(t)},bindData:function(){var i=this,n=this.data();n.trigger&&e.each(this.events,function(e,r){var a;(a=r.indexOf(".data"))>-1&&(e=t.isFunction(e)?e:i[e],i.listenTo(n,r.slice(0,a),e))})},setup:t.noop,render:function(){var e,i;this.beforeRender()!==!1&&(this.trigger("rendering"),this.template&&"function"==typeof this.template&&(e=this.dataSerialized(),i=e&&t.isArray(e),((this.forceRender||this.renderedOnce)&&e||!this.renderedOnce&&(i&&e.length>0||!i))&&(this.$el.empty().html(this.template(e)),this.renderedOnce=!0,this.$el.find("[data-view]").each(function(){o(this)}))),this.afterRender(),this.trigger("rendered"))},beforeRender:t.noop,afterRender:t.noop,data:function(){return this.model?this.model:this.collection?this.collection:{}},clearData:function(){var t=this.data();return this.unbindData(),this.model=null,this.collection=null,this.trigger("undata",t),this},setData:function(t){var e=null;return this.unbindData(),t.model?this.model=e=t.model:t.collection&&(this.collection=e=t.collection),this.bindData(),e&&e.trigger&&e.trigger("ready",e,this),this},dataSerialized:function(){var t=this.data();return t.toJSON?t.toJSON({computedFields:!0}):t},remove:function(){this.parent?c[this.parent].removeChild(this):(this.destroy(),this.trigger("removed"),this.stopListening(),this.$el.off("destroyed"),this.$el.remove(),delete c[this.cid]),this._superStop()},destroy:t.noop,trigger:function(t,e){this.$el.trigger(t,{view:this,data:e||{}})||this._superStop()},setParent:function(t){this.parent=null,t&&(this.parent=t.cid)},addChild:function(t){e.contains(t.cid,this.children)||this.children.push(t.cid)},removeChild:function(t){var i=e.indexOf(this.children,t.cid);i>-1&&(this.children.splice(i,1),t.setParent(null),t.remove())},allChildren:function(){return e.map(this.children,function(t){return d.getViewFromCid(t)})},findChildren:function(t){return e.compact(e.map(this.children,function(e){var i;return(i=d.getViewFromCid(e))&&i.instanceOf==t?i:void 0}))},findChild:function(e){var i=null;if(e instanceof t)i=d.getViewFromEl(e);else if("string"==typeof e&&(i=d.getViewFromCid(e),!i))for(var n=0;this.children.length>n;n++){var r;(r=d.getViewFromCid(this.children[n]))&&r.instanceOf==e&&(i=r)}return i},isMyElement:function(e){var i=e instanceof t?e:t(e);return i.parents("[data-view]").first().attr("data-cid")==this.cid}}]),d}); \ No newline at end of file diff --git a/bower.json b/bower.json index d00493b..2ddb0fa 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "backbone-fiber", - "version": "0.1.3", + "version": "0.1.4", "ignore": [ "bower_components", "node_modules", diff --git a/package.json b/package.json index 143de5d..658d03a 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "Backbone.Fiber", "title": "", "description": "", - "version": "0.1.3", + "version": "0.1.4", "author": { "name": "Ben Olson", "url": "http://bseth99.github.com/"