Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

change render order, make version 0.2.0

  • Loading branch information...
commit 11ece82910c0213d6ead61ae9bb129200a317860 1 parent f6b5ae6
Chad Pytel authored
View
1  .gitignore
@@ -1 +1,2 @@
*.gem
+*.swp
View
12 CHANGELOG
@@ -0,0 +1,12 @@
+0.2.0
+
+The version changes the order of the when a view has render called on it when
+it is being swapped by a SwappingRouter. This fixes some browsers which would
+display a flash of unstyled content when performing certain actions in their
+render, like changing the body class. It introduces the requirement that all
+views return an instance of themselves when rendered (a fairly standard
+backbone convention).
+
+0.0.1
+
+Initial Version
View
6 README.md
@@ -14,7 +14,8 @@ A Router subclass the provides a standard way to swap one view for another.
This introduces a convention that all views have a `leave()` function,
responsible for unbinding and cleaning up the view. And the convention that
all actions underneath the same `Router` share the same root element, and
-define it as `el` on the router.
+define it as `el` on the router. It also requires that all view's render
+method returns the view itself (a fairly standard backbone convention).
Now, a `SwappingRouter` can take advantage of the `leave()` function, and
clean up any existing views before swapping to a new one. It swaps into a new
@@ -26,8 +27,7 @@ view by rendering that view into its own `el`:
}
this.currentView = newView;
- this.currentView.render();
- $(this.el).empty().append(this.currentView.el);
+ $(this.el).empty().append(this.currentView.render().el);
}
An example SwappingRouter would look as follows:
View
3  lib/assets/javascripts/backbone-support/swapping_router.js
@@ -9,8 +9,7 @@ _.extend(Support.SwappingRouter.prototype, Backbone.Router.prototype, {
}
this.currentView = newView;
- this.currentView.render();
- $(this.el).empty().append(this.currentView.el);
+ $(this.el).empty().append(this.currentView.render().el);
}
});
View
2  lib/backbone-support/version.rb
@@ -1,3 +1,3 @@
module BackboneSupport
- VERSION = '0.0.1'.freeze
+ VERSION = '0.2.0'.freeze
end
Please sign in to comment.
Something went wrong with that request. Please try again.