jsbus 0.1.1 → 0.1.2
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/lib/jsbus.rb +2 -2
- data/lib/jsbus/engine.rb +5 -5
- data/lib/jsbus/railtie.rb +3 -3
- data/lib/jsbus/version.rb +3 -3
- data/vendor/assets/javascripts/jsbus.js +137 -130
- metadata +3 -3
data/lib/jsbus.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
require_relative './jsbus/engine'
|
2
|
-
require_relative './jsbus/railtie'
|
1
|
+
require_relative './jsbus/engine'
|
2
|
+
require_relative './jsbus/railtie'
|
3
3
|
require_relative './jsbus/version'
|
data/lib/jsbus/engine.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require 'rails/engine'
|
2
|
-
|
3
|
-
module JsBus
|
4
|
-
class Engine < ::Rails::Engine
|
5
|
-
end
|
1
|
+
require 'rails/engine'
|
2
|
+
|
3
|
+
module JsBus
|
4
|
+
class Engine < ::Rails::Engine
|
5
|
+
end
|
6
6
|
end
|
data/lib/jsbus/railtie.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module JsBus
|
2
|
-
class Railtie < ::Rails::Railtie
|
3
|
-
end
|
1
|
+
module JsBus
|
2
|
+
class Railtie < ::Rails::Railtie
|
3
|
+
end
|
4
4
|
end
|
data/lib/jsbus/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module JsBus
|
2
|
-
VERSION = "0.1.
|
3
|
-
end
|
1
|
+
module JsBus
|
2
|
+
VERSION = "0.1.2"
|
3
|
+
end
|
@@ -1,130 +1,137 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
}
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
var eventTypes
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
}
|
74
|
-
}
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
1
|
+
// Generated by CoffeeScript 1.4.0
|
2
|
+
(function() {
|
3
|
+
var Event, EventBus, Subscriber, createAndPublishEvent, isFunction, pushEventToSubscribers, root, subscribeToEventType;
|
4
|
+
|
5
|
+
root = typeof exports !== "undefined" && exports !== null ? exports : this;
|
6
|
+
|
7
|
+
EventBus = (function() {
|
8
|
+
|
9
|
+
function EventBus() {
|
10
|
+
this.subscribers = [];
|
11
|
+
}
|
12
|
+
|
13
|
+
EventBus.prototype.publish = function(eventType, data, callback) {
|
14
|
+
var eventTypes;
|
15
|
+
eventTypes = [].concat(eventType);
|
16
|
+
if (isFunction(data)) {
|
17
|
+
callback = data;
|
18
|
+
data = {};
|
19
|
+
}
|
20
|
+
return createAndPublishEvent(this, eventTypes, data, callback);
|
21
|
+
};
|
22
|
+
|
23
|
+
EventBus.prototype.reset = function() {
|
24
|
+
return this.subscribers = [];
|
25
|
+
};
|
26
|
+
|
27
|
+
EventBus.prototype.subscribe = function(eventType, callback) {
|
28
|
+
var eventTypes;
|
29
|
+
eventTypes = [].concat(eventType);
|
30
|
+
return subscribeToEventType(this, eventTypes, callback);
|
31
|
+
};
|
32
|
+
|
33
|
+
EventBus.prototype.unsubscribe = function(eventType) {
|
34
|
+
var eventTypes, subscriber, tmpSubscribers, _i, _j, _len, _len1, _ref, _results;
|
35
|
+
eventTypes = [].concat(eventType);
|
36
|
+
_results = [];
|
37
|
+
for (_i = 0, _len = eventTypes.length; _i < _len; _i++) {
|
38
|
+
eventType = eventTypes[_i];
|
39
|
+
tmpSubscribers = [];
|
40
|
+
_ref = this.subscribers;
|
41
|
+
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
|
42
|
+
subscriber = _ref[_j];
|
43
|
+
if (subscriber.eventType !== eventType) {
|
44
|
+
tmpSubscribers.push(subscriber);
|
45
|
+
} else {
|
46
|
+
this.publish("EventBus.unsubscribed", {
|
47
|
+
subscriber: subscriber
|
48
|
+
});
|
49
|
+
}
|
50
|
+
}
|
51
|
+
_results.push(this.subscribers = tmpSubscribers);
|
52
|
+
}
|
53
|
+
return _results;
|
54
|
+
};
|
55
|
+
|
56
|
+
return EventBus;
|
57
|
+
|
58
|
+
})();
|
59
|
+
|
60
|
+
Event = (function() {
|
61
|
+
|
62
|
+
function Event(eventType, data, callback) {
|
63
|
+
this.eventType = eventType;
|
64
|
+
this.data = data != null ? data : {};
|
65
|
+
this.callback = callback;
|
66
|
+
}
|
67
|
+
|
68
|
+
Event.prototype.push = function(subscriber) {
|
69
|
+
var response, _ref;
|
70
|
+
response = (_ref = subscriber.callback(this)) != null ? _ref : {};
|
71
|
+
if (isFunction(this.callback)) {
|
72
|
+
return this.callback(response);
|
73
|
+
}
|
74
|
+
};
|
75
|
+
|
76
|
+
return Event;
|
77
|
+
|
78
|
+
})();
|
79
|
+
|
80
|
+
Subscriber = (function() {
|
81
|
+
|
82
|
+
function Subscriber(eventType, callback) {
|
83
|
+
this.eventType = eventType;
|
84
|
+
this.callback = callback;
|
85
|
+
}
|
86
|
+
|
87
|
+
return Subscriber;
|
88
|
+
|
89
|
+
})();
|
90
|
+
|
91
|
+
createAndPublishEvent = function(eventBus, eventTypes, eventData, callback) {
|
92
|
+
var event, eventType, _i, _len, _results;
|
93
|
+
_results = [];
|
94
|
+
for (_i = 0, _len = eventTypes.length; _i < _len; _i++) {
|
95
|
+
eventType = eventTypes[_i];
|
96
|
+
event = new Event(eventType, eventData, callback);
|
97
|
+
_results.push(pushEventToSubscribers(eventBus, event));
|
98
|
+
}
|
99
|
+
return _results;
|
100
|
+
};
|
101
|
+
|
102
|
+
isFunction = function(obj) {
|
103
|
+
return !!(obj && obj.constructor && obj.call && obj.apply);
|
104
|
+
};
|
105
|
+
|
106
|
+
pushEventToSubscribers = function(eventBus, event) {
|
107
|
+
var subscriber, _i, _len, _ref, _results;
|
108
|
+
_ref = eventBus.subscribers;
|
109
|
+
_results = [];
|
110
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
111
|
+
subscriber = _ref[_i];
|
112
|
+
if (subscriber.eventType === event.eventType) {
|
113
|
+
_results.push(event.push(subscriber));
|
114
|
+
}
|
115
|
+
}
|
116
|
+
return _results;
|
117
|
+
};
|
118
|
+
|
119
|
+
subscribeToEventType = function(eventBus, eventTypes, callback) {
|
120
|
+
var eventType, subscriber, _i, _len, _results;
|
121
|
+
_results = [];
|
122
|
+
for (_i = 0, _len = eventTypes.length; _i < _len; _i++) {
|
123
|
+
eventType = eventTypes[_i];
|
124
|
+
subscriber = new Subscriber(eventType, callback);
|
125
|
+
eventBus.subscribers.push(subscriber);
|
126
|
+
_results.push(eventBus.publish("EventBus.subscribed", {
|
127
|
+
subscriber: subscriber
|
128
|
+
}));
|
129
|
+
}
|
130
|
+
return _results;
|
131
|
+
};
|
132
|
+
|
133
|
+
if (!root.eventBus) {
|
134
|
+
root.eventBus = new EventBus();
|
135
|
+
}
|
136
|
+
|
137
|
+
}).call(this);
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsbus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
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: 2013-02-
|
12
|
+
date: 2013-02-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
@@ -59,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
59
|
version: '0'
|
60
60
|
requirements: []
|
61
61
|
rubyforge_project:
|
62
|
-
rubygems_version: 1.8.
|
62
|
+
rubygems_version: 1.8.23
|
63
63
|
signing_key:
|
64
64
|
specification_version: 3
|
65
65
|
summary: Event bus for JavaScript
|