sinatra-cometio 0.0.7 → 0.0.8

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/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.0.8 2012-11-22
2
+
3
+ * io.once in client side.
4
+
1
5
  === 0.0.7 2012-11-22
2
6
 
3
7
  * add sinatra helper "cometio_url"
data/lib/js/cometio.js CHANGED
@@ -56,21 +56,30 @@ var CometIO = function(){
56
56
  };
57
57
 
58
58
  this.events = new Array();
59
- this.on = function(type, listener){
59
+ this.on = function(type, listener, opts){
60
60
  if(typeof listener !== "function") return;
61
61
  var event_id = self.events.length > 0 ? 1 + self.events[self.events.length-1].id : 0
62
- self.events.push({
62
+ var params = {
63
63
  id: event_id,
64
64
  type: type,
65
65
  listener: listener
66
- });
66
+ };
67
+ for(i in opts){
68
+ if(!params[i]) params[i] = opts[i];
69
+ };
70
+ self.events.push(params);
67
71
  return event_id;
68
72
  };
69
73
 
74
+ this.once = function(type, listener){
75
+ this.on(type, listener, {once: true});
76
+ };
77
+
70
78
  this.emit = function(type, data){
71
79
  for(var i = 0; i < self.events.length; i++){
72
80
  var e = self.events[i];
73
81
  if(e.type == type) e.listener(data);
82
+ if(e.once) this.removeListener(e.id);
74
83
  }
75
84
  };
76
85
 
@@ -1,3 +1,3 @@
1
1
  module SinatraCometio
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-cometio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -194,7 +194,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
194
194
  version: '0'
195
195
  segments:
196
196
  - 0
197
- hash: -1862944850052237251
197
+ hash: -4407411256198505630
198
198
  required_rubygems_version: !ruby/object:Gem::Requirement
199
199
  none: false
200
200
  requirements: