tentjs-rails 0.0.2 → 0.1.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.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Tentjs::Rails
1
+ # tentjs-rails
2
2
 
3
3
  Tent.js is a lightweight structure built on top of Backbone.js
4
4
 
@@ -24,6 +24,46 @@ Rather than extending Backbone prototypes directly, Tent builds on top of them.
24
24
  view = new Tent.View();
25
25
  ```
26
26
 
27
+ ## Tent.PubSub
28
+
29
+ Tent includes a handy global event dispatcher called `Tent.Dispatcher`. Anything that includes the `Tent.PubSub` module is able to communicate with this dispatcher like so:
30
+
31
+ ### Subscribing to events
32
+
33
+ The `subscribe` function ensures that a callback is fired when the dispatcher sees the specified event.
34
+
35
+ ```
36
+ view.subscribe('some:event', view.doSomething)
37
+ ```
38
+
39
+ ### Unsubscribing from events
40
+
41
+ Calling `unsubscribe` with an event and a callback unsubscribes that callback from the specified event. Specifying a callback with no event unsubscribes that callback from all events. Specifying an event with no callback unsubscribes all callbacks from that event for the calling object.
42
+ Calling `unsubscribe` with no arguments unsubscribes the calling object completely from the dispatcher events.
43
+
44
+ ```
45
+ view.unsubscribe('an:event', view.doSomething);
46
+ view.unsubscribe(null, view.doSomething);
47
+ view.unsubscribe('an:event');
48
+ view.unsubscribe();
49
+ ```
50
+
51
+ ### Publishing events
52
+
53
+ An object can publish events to the dispatcher using `publish`.
54
+
55
+ ```
56
+ view.publish('some:event', anArgument, anotherArgument);
57
+ ```
58
+
59
+ ### Using Tent.PubSub
60
+
61
+ To include Tent.PubSub in an object prototype:
62
+
63
+ ```
64
+ _.extend(Something.prototype, Tent.PubSub);
65
+ ```
66
+
27
67
  ## Tent.View
28
68
 
29
69
  ### Binding to an object
@@ -14,8 +14,6 @@
14
14
  _.each(this.collection.models, function (model) {
15
15
  that._modelViews[model.cid] = new options.modelView({ model: model });
16
16
  });
17
-
18
- this.render();
19
17
  },
20
18
 
21
19
  close: function () {
@@ -24,6 +22,8 @@
24
22
  _.each(this._modelViews, function (view) {
25
23
  view.close();
26
24
  });
25
+
26
+ this._isRendered = false;
27
27
  },
28
28
 
29
29
  render: function () {
@@ -33,13 +33,18 @@
33
33
  that.$el.append(view.render().el);
34
34
  });
35
35
 
36
+ this._isRendered = true;
37
+
36
38
  return this;
37
39
  },
38
40
 
39
41
  _collectionAdd: function () {
40
42
  var model = this.collection.last();
41
43
  this._modelViews[model.cid] = new Tent.ModelView({ model: model });
42
- this.$el.append(this._modelViews[model.cid].render().el);
44
+
45
+ if (this._isRendered) {
46
+ this.$el.append(this._modelViews[model.cid].render().el);
47
+ }
43
48
  },
44
49
 
45
50
  _collectionRemove: function (model) {
@@ -1,13 +1,14 @@
1
1
  (function () {
2
2
  Tent.ModelView = Tent.View.extend({
3
3
  initialize: function () {
4
- this.el.setAttribute('data-tent-model-cid', this.model.cid);
4
+ this.el.setAttribute('data-model-cid', this.model.cid);
5
5
  this._setAttributes();
6
6
  this.bindTo(this.model, 'change', this._modelChanged);
7
7
  },
8
8
  _setAttributes: function () {
9
+ var that = this;
9
10
  var attributes = this.model.serialize();
10
- this.el.setAttribute('data-tent-model-attributes', attributes);
11
+ this.el.setAttribute('data-model-attributes', attributes);
11
12
  },
12
13
  _modelChanged: function () {
13
14
  this._setAttributes();
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tentjs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-25 00:00:00.000000000 Z
12
+ date: 2012-06-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties