Permalink
Browse files

changed license formatting and removed dead code path from source

  • Loading branch information...
1 parent a8ee9d8 commit 3c8a8c361590b3ca89b6aeb6ed8ba2eaa63824de @tbranyen committed Sep 29, 2012
Showing with 62 additions and 16 deletions.
  1. +5 −6 backbone.layoutmanager.js
  2. +10 −10 license
  3. +47 −0 test/views.js
View
@@ -128,11 +128,6 @@ var LayoutManager = Backbone.View.extend({
// Instance overrides take precedence, fallback to prototype options.
options = view._options();
- // Set up the View, if it's not already managed.
- if (!view.__manager__) {
- LayoutManager.setupView(view, options);
- }
-
// Custom template render function.
view.render = function(done) {
var viewDeferred = options.deferred();
@@ -630,7 +625,8 @@ var LayoutManager = Backbone.View.extend({
// If this view has already rendered, simply call the callback.
if (parent.__manager__.hasRendered) {
- return options.when([manager.viewDeferred, parent.__manager__.viewDeferred]).then(function() {
+ return options.when([manager.viewDeferred,
+ parent.__manager__.viewDeferred]).then(function() {
done.call(view);
});
}
@@ -699,6 +695,9 @@ var LayoutManager = Backbone.View.extend({
// Only allow force if View contains a parent.
force = force && manager.parent;
+ // Ensure that cleanup is called correctly when `_removeView` is triggered.
+ LayoutManager.cleanViews(view);
+
// Only remove views that do not have `keep` attribute set, unless the
// force flag is set.
if (!keep && (manager.append === true || force) && manager.hasRendered) {
View
20 license
@@ -1,19 +1,19 @@
Copyright (c) 2012 Tim Branyen
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
View
@@ -1312,3 +1312,50 @@ asyncTest("Views intermittently render multiple times", 1, function() {
start();
});
});
+
+// https://github.com/tbranyen/backbone.layoutmanager/issues/165
+asyncTest("Events in deeply nested views being lost", function() {
+ var count = 0;
+ var treeView;
+
+ // Simulate the same problamatic View.
+ var TreeView = Backbone.LayoutView.extend({
+ className: "test",
+
+ events: {
+ "click": "hit"
+ },
+
+ hit: function() {
+ count++;
+ }
+ });
+
+ var AttributesNodeView = Backbone.LayoutView.extend({
+ beforeRender: function() {
+ treeView = this.insertView(new TreeView());
+ }
+ });
+
+ var pageView = new Backbone.LayoutView({
+ views: {
+ "": new AttributesNodeView()
+ }
+ });
+
+ // Initial rendering.
+ pageView.render();
+
+ // Re-render a few times on various levels.
+ $.when(
+ treeView.render(),
+ treeView.__manager__.parent.render()
+ ).then(function() {
+ // Trigger the event.
+ pageView.$(".test").trigger("click");
+ console.log(pageView.$(".test").length);
+
+ equals(count, 1, "Event triggered correctly");
+ start();
+ });
+});

0 comments on commit 3c8a8c3

Please sign in to comment.