Advertisement
Guest User

Untitled

a guest
May 25th, 2015
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.25 KB | None | 0 0
  1. diff --git a/src/collection-view.js b/src/collection-view.js
  2. index 74c6ce5..b0eb21c 100644
  3. --- a/src/collection-view.js
  4. +++ b/src/collection-view.js
  5. @@ -91,7 +91,6 @@ Marionette.CollectionView = Marionette.AbstractView.extend({
  6. }
  7.  
  8. if (this._shouldAddChild(child, index)) {
  9. - this.destroyEmptyView();
  10. var ChildView = this.getChildView(child);
  11. this.addChild(child, ChildView, index);
  12. }
  13. @@ -101,7 +100,6 @@ Marionette.CollectionView = Marionette.AbstractView.extend({
  14. _onCollectionRemove: function(model) {
  15. var view = this.children.findByModel(model);
  16. this.removeChildView(view);
  17. - this.checkEmpty();
  18. },
  19.  
  20. _onBeforeShowCalled: function() {
  21. @@ -186,9 +184,6 @@ Marionette.CollectionView = Marionette.AbstractView.extend({
  22. }
  23. },
  24.  
  25. - // Internal reference to what index a `emptyView` is.
  26. - _emptyViewIndex: -1,
  27. -
  28. // Internal method. Separated so that CompositeView can append to the childViewContainer
  29. // if necessary
  30. _appendReorderedChildren: function(children) {
  31. @@ -199,19 +194,14 @@ Marionette.CollectionView = Marionette.AbstractView.extend({
  32. // more control over events being triggered, around the rendering
  33. // process
  34. _renderChildren: function() {
  35. - this.destroyEmptyView();
  36. - this.destroyChildren({checkEmpty: false});
  37. + this.destroyChildren();
  38.  
  39. var models = this._filteredSortedModels();
  40. - if (this.isEmpty(this.collection, {processedModels: models})) {
  41. - this.showEmptyView();
  42. - } else {
  43. - this.triggerMethod('before:render:collection', this);
  44. - this.startBuffering();
  45. - this.showCollection(models);
  46. - this.endBuffering();
  47. - this.triggerMethod('render:collection', this);
  48. - }
  49. + this.triggerMethod('before:render:collection', this);
  50. + this.startBuffering();
  51. + this.showCollection(models);
  52. + this.endBuffering();
  53. + this.triggerMethod('render:collection', this);
  54. },
  55.  
  56. // Internal method to loop through collection and show each child view.
  57. @@ -256,83 +246,6 @@ Marionette.CollectionView = Marionette.AbstractView.extend({
  58. }
  59. return models;
  60. },
  61. -
  62. - // Internal method to show an empty view in place of
  63. - // a collection of child views, when the collection is empty
  64. - showEmptyView: function() {
  65. - var EmptyView = this.getEmptyView();
  66. -
  67. - if (EmptyView && !this._showingEmptyView) {
  68. - this.triggerMethod('before:render:empty');
  69. -
  70. - this._showingEmptyView = true;
  71. - var model = new Backbone.Model();
  72. - this.addEmptyView(model, EmptyView);
  73. -
  74. - this.triggerMethod('render:empty');
  75. - }
  76. - },
  77. -
  78. - // Internal method to destroy an existing emptyView instance
  79. - // if one exists. Called when a collection view has been
  80. - // rendered empty, and then a child is added to the collection.
  81. - destroyEmptyView: function() {
  82. - if (this._showingEmptyView) {
  83. - this.triggerMethod('before:remove:empty');
  84. -
  85. - this.destroyChildren();
  86. - delete this._showingEmptyView;
  87. -
  88. - this.triggerMethod('remove:empty');
  89. - }
  90. - },
  91. -
  92. - // Retrieve the empty view class
  93. - getEmptyView: function() {
  94. - return this.getOption('emptyView');
  95. - },
  96. -
  97. - // Render and show the emptyView. Similar to addChild method
  98. - // but "add:child" events are not fired, and the event from
  99. - // emptyView are not forwarded
  100. - addEmptyView: function(child, EmptyView) {
  101. -
  102. - // get the emptyViewOptions, falling back to childViewOptions
  103. - var emptyViewOptions = this.getOption('emptyViewOptions') ||
  104. - this.getOption('childViewOptions');
  105. -
  106. - if (_.isFunction(emptyViewOptions)) {
  107. - emptyViewOptions = emptyViewOptions.call(this, child, this._emptyViewIndex);
  108. - }
  109. -
  110. - // build the empty view
  111. - var view = this.buildChildView(child, EmptyView, emptyViewOptions);
  112. -
  113. - view._parent = this;
  114. -
  115. - // Proxy emptyView events
  116. - this.proxyChildEvents(view);
  117. -
  118. - // trigger the 'before:show' event on `view` if the collection view
  119. - // has already been shown
  120. - if (this._isShown) {
  121. - Marionette.triggerMethodOn(view, 'before:show', view);
  122. - }
  123. -
  124. - // Store the `emptyView` like a `childView` so we can properly
  125. - // remove and/or close it later
  126. - this.children.add(view);
  127. -
  128. - // Render it and show it
  129. - this.renderChildView(view, this._emptyViewIndex);
  130. -
  131. - // call the 'show' method if the collection view
  132. - // has already been shown
  133. - if (this._isShown) {
  134. - Marionette.triggerMethodOn(view, 'show', view);
  135. - }
  136. - },
  137. -
  138. // Retrieve the `childView` class, either from `this.options.childView`
  139. // or from the `childView` in the object definition. The "options"
  140. // takes precedence.
  141. @@ -459,25 +372,6 @@ Marionette.CollectionView = Marionette.AbstractView.extend({
  142. return view;
  143. },
  144.  
  145. - // check if the collection is empty
  146. - // or optionally whether an array of pre-processed models is empty
  147. - isEmpty: function(collection, options) {
  148. - var models;
  149. - if (_.result(options, 'processedModels')) {
  150. - models = options.processedModels;
  151. - } else {
  152. - models = this.collection ? this.collection.models : [];
  153. - models = this._filterModels(models);
  154. - }
  155. - return models.length === 0;
  156. - },
  157. -
  158. - // If empty, show the empty view
  159. - checkEmpty: function() {
  160. - if (this.isEmpty(this.collection)) {
  161. - this.showEmptyView();
  162. - }
  163. - },
  164.  
  165. // You might need to override this if you've overridden attachHtml
  166. attachBuffer: function(collectionView) {
  167. @@ -548,7 +442,7 @@ Marionette.CollectionView = Marionette.AbstractView.extend({
  168. if (this.isDestroyed) { return this; }
  169.  
  170. this.triggerMethod('before:destroy:collection');
  171. - this.destroyChildren({checkEmpty: false});
  172. + this.destroyChildren();
  173. this.triggerMethod('destroy:collection');
  174.  
  175. return Marionette.AbstractView.prototype.destroy.apply(this, arguments);
  176. @@ -558,18 +452,11 @@ Marionette.CollectionView = Marionette.AbstractView.extend({
  177. // is holding on to, if any
  178. destroyChildren: function(options) {
  179. var destroyOptions = options || {};
  180. - var shouldCheckEmpty = true;
  181. var childViews = this.children.map(_.identity);
  182.  
  183. - if (!_.isUndefined(destroyOptions.checkEmpty)) {
  184. - shouldCheckEmpty = destroyOptions.checkEmpty;
  185. - }
  186.  
  187. this.children.each(this.removeChildView, this);
  188.  
  189. - if (shouldCheckEmpty) {
  190. - this.checkEmpty();
  191. - }
  192. return childViews;
  193. },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement