backbone-support 0.0.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ *.swp
@@ -0,0 +1,12 @@
1
+ 0.2.0
2
+
3
+ The version changes the order of the when a view has render called on it when
4
+ it is being swapped by a SwappingRouter. This fixes some browsers which would
5
+ display a flash of unstyled content when performing certain actions in their
6
+ render, like changing the body class. It introduces the requirement that all
7
+ views return an instance of themselves when rendered (a fairly standard
8
+ backbone convention).
9
+
10
+ 0.0.1
11
+
12
+ Initial Version
data/README.md CHANGED
@@ -1,11 +1,16 @@
1
- Helper and utility classes that fill out Backbone for serious development.
1
+ There's no built-in garbage collection for Backbone’s event bindings, and
2
+ forgetting to unbind can cause bugs and memory leaks.
3
+
4
+ Backbone Support currently provides two utility classes, SwappingRouter and CompositeView,
5
+ that introduce a `leave()` function, which unbinds and cleans up the view.
6
+ They should be used where views are instantiated (in Router instances and in composite views).
2
7
 
3
8
  Inspired by our projects and the Backbone.js on Rails book:
4
9
  http://workshops.thoughtbot.com/backbone-js-on-rails
5
10
 
6
11
  The book contains complete instructions and in-depth coverage of the internals
7
- of CompositeView and Swappingrouter, and an example application that shows
8
- their usage
12
+ of CompositeView and SwappingRouter, and an example application that shows
13
+ their usage.
9
14
 
10
15
  ### SwappingRouter
11
16
 
@@ -14,7 +19,8 @@ A Router subclass the provides a standard way to swap one view for another.
14
19
  This introduces a convention that all views have a `leave()` function,
15
20
  responsible for unbinding and cleaning up the view. And the convention that
16
21
  all actions underneath the same `Router` share the same root element, and
17
- define it as `el` on the router.
22
+ define it as `el` on the router. It also requires that all view's render
23
+ method returns the view itself (a fairly standard backbone convention).
18
24
 
19
25
  Now, a `SwappingRouter` can take advantage of the `leave()` function, and
20
26
  clean up any existing views before swapping to a new one. It swaps into a new
@@ -24,10 +30,9 @@ view by rendering that view into its own `el`:
24
30
  if (this.currentView && this.currentView.leave) {
25
31
  this.currentView.leave();
26
32
  }
27
-
33
+
28
34
  this.currentView = newView;
29
- this.currentView.render();
30
- $(this.el).empty().append(this.currentView.el);
35
+ $(this.el).empty().append(this.currentView.render().el);
31
36
  }
32
37
 
33
38
  An example SwappingRouter would look as follows:
@@ -74,7 +79,7 @@ maintain a back-reference at `this.parent`. This is used to reach up and call
74
79
 
75
80
  You'll need these, but chances are you already have them in your app:
76
81
 
77
- * jQuery
82
+ * jQuery or Zepto
78
83
  * Underscore
79
84
  * Backbone
80
85
 
@@ -131,7 +136,7 @@ First off:
131
136
  In your `config/application.rb`:
132
137
 
133
138
  ``` ruby
134
- config.middleware.use Rack::Static,
139
+ config.middleware.use Rack::Static,
135
140
  :urls => ['/vendor/plugins/backbone-support/lib/assets/javascripts']
136
141
  ```
137
142
 
@@ -157,7 +162,6 @@ end
157
162
  Your individual specs will then need the full root path in `require`. For
158
163
  example:
159
164
 
160
-
161
165
  ``` js
162
166
  requirePublic = function(path) {
163
167
  require("/public/javascripts/" + path);
@@ -9,8 +9,7 @@ _.extend(Support.SwappingRouter.prototype, Backbone.Router.prototype, {
9
9
  }
10
10
 
11
11
  this.currentView = newView;
12
- this.currentView.render();
13
- $(this.el).empty().append(this.currentView.el);
12
+ $(this.el).empty().append(this.currentView.render().el);
14
13
  }
15
14
  });
16
15
 
@@ -1,3 +1,3 @@
1
1
  module BackboneSupport
2
- VERSION = '0.0.1'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
@@ -14,6 +14,8 @@ src_files:
14
14
  - vendor/jquery.js
15
15
  - vendor/underscore.js
16
16
  - vendor/backbone.js
17
+ - lib/assets/javascripts/backbone-support.js
18
+ - lib/assets/javascripts/backbone-support/support.js
17
19
  - lib/**/*.js
18
20
 
19
21
  # spec_files
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backbone-support
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 2
8
9
  - 0
9
- - 1
10
- version: 0.0.1
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chad Pytel
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2011-11-29 00:00:00 Z
21
+ date: 2012-01-23 00:00:00 Z
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
24
24
  name: jasmine
@@ -44,6 +44,8 @@ extensions: []
44
44
  extra_rdoc_files: []
45
45
 
46
46
  files:
47
+ - .gitignore
48
+ - CHANGELOG
47
49
  - Gemfile
48
50
  - Gemfile.lock
49
51
  - LICENSE